Question 11
EasyHow many destructors can a C++ class have?
- A.
None
- B.
Any number
- C.
Exactly one
- D.
Two
Sign up free to see the answer and a step-by-step explanation.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Object-Oriented Programming
How many destructors can a C++ class have?
None
Any number
Exactly one
Two
Sign up free to see the answer and a step-by-step explanation.
Which character begins the name of a destructor in C++?
! (exclamation)
& (ampersand)
~ (tilde)
Sign up free to see the answer and a step-by-step explanation.
Does Java have destructors like C++?
No; the garbage collector frees unused objects automatically
Yes, written with ~
Only for static classes
Yes, called finalise() and run immediately
Sign up free to see the answer and a step-by-step explanation.
If a Java class defines no constructor at all, what does the compiler provide?
A constructor with every field as a parameter
Nothing; objects cannot be created
A destructor
A default constructor with no parameters
Sign up free to see the answer and a step-by-step explanation.
A Java class defines only a constructor that takes a String. Does the compiler still add a no-argument constructor?
Yes, always
No
Only if the class is abstract
Only if the class is public
Sign up free to see the answer and a step-by-step explanation.
In C++, what is a constructor's member initialiser list?
The part after the colon that initialises members before the constructor body runs
A list of all objects created
A list of the class's methods
An array passed to the constructor
Sign up free to see the answer and a step-by-step explanation.
In Python, which method is called when an object is about to be destroyed?
del
init
end
exit
Sign up free to see the answer and a step-by-step explanation.
Can a constructor be declared static in Java?
Only in abstract classes
Yes
No
Only in interfaces
Sign up free to see the answer and a step-by-step explanation.
What must a constructor's name be in C++ and Java?
The same as the class's name
init
Any name the programmer chooses
constructor
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
class P:
def __init__(self, n="Guest"):
self.n = n
print(P().n, P("Asha").n)
Error
Guest Asha
Guest Guest
Asha Asha
Sign up free to see the answer and a step-by-step explanation.