constructor is a class method that gets automatically executed whenever class’s object is created or whenever class is initialized
– Constructor does not have any return type
– Construtctor have the same name of the class
1.Instance or Default Constructor:——–
Constructor called implicitly when we create the class instance, the modifiers can be public, private, protected, and internal or protected internal.
2. static Constructor——— will call only once when the class gets loaded in the memory without creating the instance of the class.
– It can only access the static members of the class.
– There can be only one static constructor in the class.
– The static constructor should be without parameters.
3. Parameterized Constructors:———-
will require initializing class members during instantiation
– same rules as default constructor and will have parameters
4. 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.