Multiple choice

With reference to classes and objects, when does a constructor of a class invoke by the C++ compiler ?

  1. When an object is used.

  2. When a class is declared.

  3. When an object is declared.

  4. When a class is used.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

A constructor is a special function, which has the same name as of the class. It is called implictly when an object is declared. The user is not required to call it explicitly like a normal method. There are three types of constructors - default, parameterized and copy constructor. A class can have more than one constructor, which is called as 'constructor overloading'