Difficulty: Easy
Correct Answer: A destructor has the same name as the class in which it is present.
Explanation:
Introduction / Context:
Destructors are special member functions that finalize objects. Their syntax, naming, and constraints differ from ordinary member functions. This question asks which property correctly describes a destructor according to the C++ language rules.
Given Data / Assumptions:
Concept / Approach:
A destructor’s declarator uses the class name preceded by a tilde: ~ClassName(). It has no return type (not even void) and cannot take parameters. There can be only one destructor per class (no overloading), though it may be virtual, defaulted, deleted, or user-defined. Therefore, the correct statement is that a destructor has the same name as the class (with a leading ~).
Step-by-Step Solution:
Verification / Alternative check:
Any attempt to declare two destructors or to assign a return type will yield compilation errors, confirming uniqueness and lack of return type.
Why Other Options Are Wrong:
Different name — false per syntax.
Returns integer — destructors return nothing.
Can be overloaded — not allowed; only one destructor is permitted.
Common Pitfalls:
Final Answer:
A destructor has the same name as the class in which it is present.
Discussion & Comments