Interviews11 answers
What is the Use of a Private Constructor in C#?
11 Answers
through private constructor we can achieve the method hiding concept in OOPS
Manoj Kumar DuraisamyPosted Jan 2, 2017, 8:55 PM EST
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 MurmuPosted Jan 15, 2016, 1:27 AM EST
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 MurmuPosted Jan 15, 2016, 1:27 AM EST
we cant create object of class
Ayyaz AhmadPosted Dec 19, 2015, 3:01 AM EST
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 DashPosted Apr 18, 2015, 9:40 PM EDT
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 ChoudharyPosted Mar 24, 2015, 5:44 PM EDT
Private constructor are used in Singleton pattern
Vijay KumarPosted Dec 19, 2014, 1:48 AM EST
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 AgrawalPosted Dec 8, 2014, 9:08 PM EST
Private constructor are used in Singleton pattern
Dhanik SahniPosted Oct 9, 2014, 5:41 AM EDT
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 naiduPosted Jul 30, 2014, 4:05 AM EDT
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 KharePosted Jul 28, 2014, 2:52 AM EDT








