Which of the following are TRUE about constructors in C++? (A) A constructor…
2024
Which of the following are TRUE about constructors in C++?
(A) A constructor can be overloaded.
(B) A constructor does not have a return type.
(C) A constructor must be declared as a friend function.
(D) A constructor is called when an object is destroyed.
Choose the correct answer from the options given below :
- A.
(B), (C), (D) Only
- B.
(B), (C) Only
- C.
(A), (B), (C) Only
- D.
(A), (B) Only.
Attempted by 115 students.
Show answer & explanation
Correct answer: D
Answer: The true statements are: 'A constructor can be overloaded' and 'A constructor does not have a return type.'
Reasons:
'A constructor can be overloaded' — True. A class may define multiple constructors that differ in their parameter lists to allow different ways of initializing objects.
'A constructor does not have a return type' — True. Constructors are special member functions and are not declared with any return type (not even void).
'A constructor must be declared as a friend function' — False. Constructors are normal special member functions of the class; they are not required to be friend functions.
'A constructor is called when an object is destroyed' — False. The destructor is invoked when an object is destroyed, not the constructor.
A video solution is available for this question — log in and enroll to watch it.