Difficulty: Easy
Correct Answer: A constructor has no return type.
Explanation:
Introduction / Context:
Constructors are special member functions that initialize objects. Their syntax and type system rules differ from ordinary functions. This question checks whether you know the correct rule for a constructor’s return type and dispels common myths about what can appear inside a constructor’s body.
Given Data / Assumptions:
Concept / Approach:
A constructor has no return type—not even void
. Attempting to specify a return type makes it an ordinary function, not a constructor, and compilation fails if you intend it to be a constructor. Inside the constructor body, you can certainly call other functions, initialize members in the member initializer list, and perform checks or throw exceptions if needed. Therefore, the correct statement is that a constructor has no return type.
Step-by-Step Solution:
Verification / Alternative check:
Try compiling int ClassName();
as a “constructor.” The compiler treats it as a normal function declaration, not a constructor, proving that constructors cannot declare a return type. Conversely, placing function calls in the body compiles and runs normally.
Why Other Options Are Wrong:
“Has a return type” or “has a void return type” contradict the language rule.
“Cannot contain a function call” is false; constructors may call functions freely (and often do).
Common Pitfalls:
Final Answer:
A constructor has no return type.
Discussion & Comments