Hello Dear,
Please Tell Me What is the purpose of a default constructor ?
Hello Dear,
Please Tell Me What is the purpose of a default constructor ?
Constructors are mostly used to initialize the instance variables.
Specifically, using default constructors the instance variables will be initialized with fixed values for all objects.
A default constructor is a constructor which can be called with no arguments, either defined with an empty parameter list, or with default arguments provided for every parameter.
A default constructor is a constructor which constitutes of no arguments, it can be said with an empty parameter list or else with default arguments that provides for every parameter.
Constructor which constitues of no arguments with empty parameters list is known as default constructor.
It is a special type of method which is used to initialize the object. Every time an object is created using the new keyword, at least one constructor is called. It calls a default constructor if there is no constructor available in the class. In such case, Java compiler provides a default constructor by default.
When you create an object, you need to initialize its data members. As you know, private and protected data members can be accessed outside the class by using public member functions of the class. C++ offers a special function, called constructor, which makes the initialization of an object. A constructor is a special function that is called every time you create an object.
Constructor is a special function which has the same name as of class name. Constructors don't have return type and they don't return any value. Default Constructor is mainly used for the initialization purpose.
|
Bookmarks