Compiler provides its default constructor to build object - Constructor and Destructor

Q.  If default constructor is not defined, then how the objects of the class will be created?
- Published on 17 Jul 15

a. The compiler will generate error
b. Error will occur at run-time.
c. Compiler provides its default constructor to build the object.
d. None of these

ANSWER: Compiler provides its default constructor to build the object.
 

    Discussion

  • ramesh   -Posted on 08 Oct 15
    Compiler provides its default constructor to build the object. Default constructor has no argument or it is parameter less constructor. If there is no constructor available in a class, the compiler implicitly creates a default parameterless constructor .If a derived class constructor does not explicitly call the base class constructor then, the default constructor for the base class is called.
    Example:
    class myClass
    {
    myClass() { } // default constructor.
    };

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)