6.6 DEFAULT CONSTRUCTOR
Objects are initialized with the help of constructor. When we create an object, at that instance, a constructor is used to initialize it. When we specify which constructor to use, there is no ambiguity. However, what if we do not specify any constructor? Consider the following definitions:
Date * d1 = new Date ; or
Date d2 ;
Now the onus is on the compiler to select the constructor. The constructor, which the compiler selects in such situation, is called the default constructor. The compiler selects the constructor without parameters. Hence, in simple terms, constructor without parameters is termed as “default” constructor.
When we try to construct an object without specifying the constructor, three distinct cases have ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access