Purpose of Default Constructor Assignment Help
A program which has a constructer without parameters is called “Default Constructor”. As we know object is nothing but an entity which has its own states and behavior meaning that it has its own data member and function member. So, here "construct the object" in turn it means that constructing the data members of the object you create. Default constructor is something which is useful to initialize the data members (Variables) to their default value when you create any object.
- If you will not provide any Constructor during the class definition. The compiler will provide you Zero Argument Constructor. That is known as Default Constructor. It is only used to initialize the class data members. That means if there is some numeric type data members then those will be initialized to 0 or 0.0 as per integral and floating point values respectively. But if there is any String type variable then it will be initialized to an empty string.
That is like
- If we do not give gives the value to the constructor so it will take the default value.
- Overridden is not possible in constructor.
- The class name and the constructor name must be same.
- Return type cannot be used in constructor.