Determine whether the following statements are true or false. If an answer is tr
ID: 3567469 • Letter: D
Question
Determine whether the following statements are true or false. If an answer is true, explain why and, where appropriate, provide an example. If the answer is false, please explain why. 1. Constructors can have names different from their classes. 2. Destructors must have the same name as their class, preceded by a tilde (~). 3. Destructors have default arguments. 4. A destructor must be declared for each class. 5. If a program uses the delete operator, a destructor is not needed. 6. Explicit constructors need to be included in every class. 7. Destructors are declared with a return type. 8. Destructors are called each time an object goes out of existence. 9. A class can have more than one constructor function. 10. A class can have several default constructor functions. 11. Default constructors can have no parameters or all parameters must have default values. 12. Constructors need to be declared for each class. 13. Constructors are declared with return types. 14. Constructors are automatically called when objects are created. 15. A class can have many destructor functions.
Explanation / Answer
1. Constructors can have names different from their classes
Ans- No, Constructors name must be same as the class name
Because the designers of the different languages you mention decided to make them that way. It is entirely possible for someone to design an OOP language where constructors do not have to have the same name as the class (as commented, this is the case in python).
It is a simple way to distinguish constructors from other functions and makes the constructing of a class in code very readable, so makes sense as a language design choice.
The mechanism is slightly different in the different languages, but essentially this is just a method call assisted by language features (the new keyword in java and c#, for example).
The constructor gets invoked by the runtime whenever a new object is created.
2. Destructors must have the same name as their class, preceded by a tilde (~).
yes, Destructors name must be same as the class name .
Reason is same as it for the contructors.
3. Destructors have default arguments.
no, destructors do not take parameters.
A special declarator syntax using an optional function-speci?er (7.1.2) followed by
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.