Constructor and destructor - placement practice test
1. A constructor that does not have any parameters is called____________ constructor.
a. Custom
b. dynamic
c. static
d. default
View Answer / Hide Answer2. Is it mandatory to invoke/call a constructor for creating an object?
a. Yes
b. No
View Answer / Hide Answer3. If default constructor is not defined, then how the objects of the class will be created?
a. The compiler will generate error
b. Error will occur at run-time.
c. Compiler provides its default constructor to build the object
d. None of these
View Answer / Hide AnswerANSWER: c. Compiler provides its default constructor to build the object
4. Which of the followings are true about constructors?
1. A class can have more than one constructor
2. They can be inherited
3. Their address can be referred
4. Constructors cannot be declared in protected section of the class
5. Constructors cannot return values
a. Only 1,2,4
b. 1,2,4,5
c. 1,3,5
d. 1,4,5
View Answer / Hide Answer5. Can constructors be overloaded?
a. Yes
b. No
View Answer / Hide AnswerANSWER: a. Yes
Explanation: Constructors are nothing but functions bearing the same name as that of the class. So, just like function overloading, constructor overloading is possible. We can have
constructor overloading through parameterized constructors differing in parameters and signature. We can also achieve it by having default constructor, parameterized constructor and copy
constructor in a class.
6. Assume class TEST. Which of the following statements is/are responsible to invoke copy constructor?
a. TEST T2(T1)
b. TEST T4 = T1
c. T2 = T1
d. both a and b
e. All of these
View Answer / Hide Answer7. Is it possible to define a constructor with default arguments?
a. Yes
b. No
View Answer / Hide AnswerANSWER: a. Yes
Explanation: As we can have function with default arguments in CPP, likewise we can have constructors with default arguments as well. And finally, constructors are also
functions.
8. Which of the following statements are not true about destructor?
1. It is invoked when object goes out of the scope
2. Like constructor, it can also have parameters
3. It can be virtual
4. It can be declared in private section
5. It bears same name as that of the class and precedes Lambda sign
a. Only 2, 3, 5
b. Only 2, 3, 4
c. Only 2, 4, 5
d. Only 3, 4, 5
View Answer / Hide Answer9. The explicit keyword is an optional decoration for the constructors that takes exactly_____argument.
a. No argument
b. Two
c. Three
d. One
View Answer / Hide Answer10. The purpose of explicit keyword is to tell the compiler that a certain constructor may not be used to implicitly cast an expression to its class type.
a. True
b. False
View Answer / Hide Answer11. Match the following.
a. P – III, Q - II, R – I
b. P – V, Q - I, R – IV
c. P – III, Q - I, R – IV
d. P – V, Q - II, R – I
View Answer / Hide AnswerANSWER: c. P – III, Q - I, R – IV