There are three types of constructors.
- Namely Default constructor.
- Parameterized constructor.
- Copy constructor.
1. Default Constructor:
A constructor which does not take any arguments is called a zero argument constructor. It is also called zero-argument constructor.
Features of default constructor are:
- All objects of a class are initialized to same set of values
- These constructors has no arguments
- These constructors are automatically called when every object is created.
The disadvantages of default constructor are:
- Different objects cannot be initialized with different values.
- Declaring a constructor with arguments hides default constructor.
2. parameterized constructor:
A constructor that takes one or more arguments is called a parameterized constructor.
The features of parameterized constructors are :
- parameterized constructors can be overloaded
- parameterized constructors can have default arguments and default values.
The different methods through which constructors can be invoked are implicit call and explicit call and using operator.
a. Explicit call:
It is a method of invoking a function where the declaration of object is followed by assignment operator followed by a constructor followed by argument list enclosed within parentheses.
b. Implicit Call:
It means the declarationof the object is followed by argument list enclosed in parentheses used with constructors The is used for the parameterized constructor which has exactly one argument.
3. Copy Constructor:
It is a parameterized constructor using which one object can be copied into another object. The copy constructor takes an object as argument and is used to copy values of data members of one object into other object.