Which of the statement are CORRECT ? (A) Constructors are invoked…
2023
Which of the statement are CORRECT ?
(A) Constructors are invoked automatically when the objects are created.
(B) Constructors do not have return types, not even void and therefore they cannot return values.
(C) Constructors cannot be inherited though a derived class can call the base class constructors.
(D) Constructors can be declared as virtual.
Choose the correct answer from the options given below :
Answer: B. (A), (B) and (C) Only — Answer: The correct statements are the following three statements from the question. Constructors are invoked automatically when the objects are created. —…
- A.
(A), (B) and (D) Only
- B.
(A), (B) and (C) Only
- C.
(B), (C) and (D) Only
- D.
(A), (C) and (D) Only
Attempted by 132 students.
Show answer & explanation
Correct answer: B
Answer: The correct statements are the following three statements from the question.
Constructors are invoked automatically when the objects are created. — True. A constructor runs to initialize a new object at the moment the object is created.
Constructors do not have return types, not even void and therefore they cannot return values. — True. Constructors are special initialization routines and are not declared with a return type.
Constructors cannot be inherited though a derived class can call the base class constructors. — Largely true in typical usage: constructors are not automatically inherited into derived classes, but a derived class can explicitly invoke base-class constructors to initialize the base part of the object.
Why the remaining statement is false:
Constructors can be declared as virtual. — False. Constructors cannot be virtual. Virtual dispatch requires an already-constructed object and a virtual table; constructors are responsible for creating the object, so they cannot participate in virtual dispatch. Use virtual destructors when you need polymorphic destruction.
Note: Since C++11 there is a facility to inherit constructors explicitly using a using-declaration (for convenience), but constructors are not inherited by default. The intended meaning of the statement in typical exam contexts is that constructors are not inherited.
A video solution is available for this question — log in and enroll to watch it.