C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
.NET
ADO.NET
Android
ASP.NET
C#
Databases & DBA
Design Patterns & Practices
iOS
Java
OOP/OOD
SharePoint
Software Testing
Web Development
WPF
View All
11
Reply
What is use of Private Constructor?
Akhil Khare
11y
3.9k
0
Reply
Delete Row
Delete Column
Insert Link
×
Insert
Cancel
Embed YouTube Video
×
Width (%)
Height (%)
Insert
Cancel
Table Options
×
Rows
Columns
First row as header
Create Table
Insert Image
×
Selected file:
Alignment
Left
Center
Right
Select an image from your device to upload
Upload to Server
Cancel
Submit
A private constructor is a special instance constructor. It is generally used in classes that contain static members only. If a class has one or more private constructors and no public constructors, other classes (except nested classes) cannot create instances of this class. class CheckConstructor {// Private Constructor: private CheckConstructor() { }public static int e = 21; }
Akhil Khare
11y
5
Private constructor are used in Singleton pattern
Vijay Kumar
11y
2
Private Constructor will restrict to creat the object of that class. it will leads to protect the data from that class with out accessing from another class.
nethaji naidu
11y
1
through private constructor we can achieve the method hiding concept in OOPS
Manoj Kumar
8y
0
creating object is possible thru public parameterized constructor(if any) of the class having private constructor. However, if the default constructor is private then we can't inherit it.
Anil Kumar Murmu
9y
0
creating object is possible thru public parameterized constructor(if any) of the class having private constructor. However, if the default constructor is private then we can't inherit it.
Anil Kumar Murmu
9y
0
we cant create object of class
Ayyaz Ahmad
10y
0
If we are using private constructor in a parent class we cannot create object of parent class and secondly we cannot access the parent class member using child class object
Debendra Dash
10y
0
Private Constructor prevent to create an instance of a class. it is mainly use when our class contain only static field or we want to use single ton architecture. class Abs { public static int ab =10; private Abs() { } } class Demo { static void Main(string[] args) { Console.WriteLine(Abs.ab.ToString()); Console.ReadLine(); } }
Pankaj Kumar Choudhary
10y
0
private constructors are used when there is no need to create the object of the class when we want to create any utility then we can use this private constructor
Vikram Agrawal
11y
0
Private constructor are used in Singleton pattern
Dhanik Sahni
11y
0
Message