Akhil Khare
What is the Use of a Private Constructor in C#?
By Akhil Khare in C# on Jul 28 2014
  • Akhil Khare
    Jul, 2014 28

    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; }

    • 5
  • Vijay Kumar
    Dec, 2014 19

    Private constructor are used in Singleton pattern

    • 2
  • nethaji naidu
    Jul, 2014 30

    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.

    • 1
  • Manoj Kumar Duraisamy
    Jan, 2017 3

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

    • 0
  • Anil Kumar Murmu
    Jan, 2016 15

    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.

    • 0
  • Anil Kumar Murmu
    Jan, 2016 15

    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.

    • 0
  • Ayyaz Ahmad
    Dec, 2015 19

    we cant create object of class

    • 0
  • Debendra Dash
    Apr, 2015 19

    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

    • 0
  • Pankaj  Kumar Choudhary
    Mar, 2015 24

    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(); } }

    • 0
  • Vikram Agrawal
    Dec, 2014 9

    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

    • 0
  • Dhanik Sahni
    Oct, 2014 9

    Private constructor are used in Singleton pattern

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS