Print Friendly and PDF
(Default Constructor) What’s a default constructor? How are an object’s data members initialized if a class has only an implicitly defined default constructor?
(Default Constructor) What’s a default constructor? How are an object’s data members initialized if a class has only an implicitly defined default constructor?

Solution:

Default constructor — a constructor with no parameters.
A constructor is a special member function that must be defined with the same name as the class so that the compiler can distinguish it from the class’s other member functions. An important difference between constructors and other functions is that constructors cannot return values, so they cannot specify a return type (not even void). Normally, constructors are declared public.

The default constructor provided by the compiler creates a class' object without giving any initial values to the object’s fundamental type data members. 

[Note: For data members that are objects of other classes, the default constructor implicitly calls each data member’s default constructor to ensure that the data member is initialized properly.
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: