Inheritance - placement practice test
1. Reusability of the code can be achieved in CPP through
a. Polymorphism
b. Encapsulation
c. Inheritance
d. Both a and c
View Answer / Hide Answer2. When a child class inherits traits from more than one parent class, this type of inheritance is called _______________ inheritance.
a. Hierarchical
b. Hybrid
c. Multilevel
d. Multiple
View Answer / Hide Answer3.class X, class Y and class Z are derived from class BASE. This is _____________ inheritance
a. Multiple
b. Multilevel
c. Hierarchical
d. Single
View Answer / Hide Answer4. The derivation of Child class from Base class is indicated by ____ symbol.
a. ::
b. :
c. ;
d. |
View Answer / Hide Answer5. During a class inheritance in CPP, if the visibility mode or mode of derivation is not provided, then by default visibility mode is___________.
a. public
b. protected
c. private
d. friend
View Answer / Hide Answer6. If the derived class is struct, then default visibility mode is_______
a. public
b. protected
c. private
d. struct can’t inherit class
View Answer / Hide AnswerANSWER: a. public
Explanation: Just like classes, structures can also inherit traits from the existing base class and vice versa.
7. Can struct be used as Base class for inheritance ?
a. Yes
b. No
View Answer / Hide AnswerANSWER: a. Yes
8. Private members of the class are not inheritable.
a. True
b. False
View Answer / Hide AnswerANSWER: b. False
Explanation: Private members of the class are inherited to derived classes but they are not accessible to the objects and members of derived class.
9. When a base class is privately inherited by the derived class, then_______________
a. protected members of the base class become private members of derived class
b. public members of the base class become private members of derived class
c. both a and b
d. only b
View Answer / Hide Answer10. When base class is derived in protected mode, then______________
1. public members of base class become private members of derived class
2. public members of base class become protected members of derived class
3. public members of base class become public members of derived class
4. protected members of base class become protected members of derived class
5. protected members of base class become private members of derived class
6. protected members of base class become public members of derived class
a. Only 1, 5
b. Only 1, 6
c. Only 2, 6
d. 2 , 4
View Answer / Hide Answer11. What is difference between protected and private access specifiers in inheritance?
a. private member is not inheritable and not accessible in derived class
b. protected member is inheritable and also accessible in derived class
c. Both are inheritable but private is accessible in the derived class
d. Both are inheritable but protected is not accessible in the derived class
View Answer / Hide AnswerANSWER: b. protected member is inheritable and also accessible in derived class
12. In case of inheritance where both base and derived class are having constructors, when an object of derived class is created then___________
a. constructor of derived class will be invoked first
b. constructor of base class will be invoked first
c. constructor of derived class will be executed first followed by base class
d. constructor of base class will be executed first followed by derived class
View Answer / Hide AnswerANSWER: d. constructor of base class will be executed first followed by derived class
13. In case of inheritance where both base and derived class are having constructor and destructor, then which if the following are true ?
1. Constructors are executed in their order of derivation
2. Constructors are executed in reverse order of derivation
3. Destructors are executed in their order of derivation
4. Destructors are executed in reverse order of derivation
a. Only 2 ,4
b. Only 1 , 3
c. Only 1 , 4
d. Only 2, 3
View Answer / Hide Answer14. Can we pass parameters to base class constructor though derived class or derived class constructor?
a. Yes
b. No
View Answer / Hide Answer15. If base class has constructor with arguments, then it is ________________ for the derived class to have constructor and pass the arguments to base class constructor.
a. Optional
b. Mandatory
c. Compiler dependent
d. Error
View Answer / Hide Answer16. In Multipath inheritance, in order to remove duplicate set of records in child class, we___________
a. Write Virtual function in parent classes
b. Write virtual functions is base class
c. Make base class as virtual base class
d. All of these
View Answer / Hide AnswerANSWER: c. Make base class as virtual base class