11
Reply

What is use of Private Constructor?

Akhil Khare

Akhil Khare

Jul 28, 2014
3.9k
0

    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
    July 28, 2014
    5

    Private constructor are used in Singleton pattern

    Vijay Kumar
    December 19, 2014
    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
    July 30, 2014
    1

    through private constructor we can achieve the method hiding concept in OOPS

    Manoj Kumar
    January 03, 2017
    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
    January 15, 2016
    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
    January 15, 2016
    0

    we cant create object of class

    Ayyaz Ahmad
    December 19, 2015
    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
    April 19, 2015
    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(); } }

    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
    December 09, 2014
    0

    Private constructor are used in Singleton pattern

    Dhanik Sahni
    October 09, 2014
    0