Inheritance - placement practice test

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 Answer

ANSWER: c. Inheritance




2. 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 Answer

ANSWER: d. Multiple




3.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 Answer

ANSWER: c. Hierarchical




4. The derivation of Child class from Base class is indicated by ____ symbol.

a. ::
b. :
c. ;
d. |
View Answer / Hide Answer

ANSWER: b. :




5. 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 Answer

ANSWER: c. private




6. 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 Answer

ANSWER: 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 Answer

ANSWER: a. Yes




8. Private members of the class are not inheritable.

a. True
b. False
View Answer / Hide Answer

ANSWER: 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 Answer

ANSWER: c. both a and b




10. 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 Answer

ANSWER: d. 2 , 4




11. 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 Answer

ANSWER: 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 Answer

ANSWER: 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 Answer

ANSWER: c. Only 1 , 4




14. Can we pass parameters to base class constructor though derived class or derived class constructor?

a. Yes
b. No
View Answer / Hide Answer

ANSWER: a. Yes




15. 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 Answer

ANSWER: b. Mandatory




16. 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 Answer

ANSWER: c. Make base class as virtual base class



Post your comment

    Discussion

  • RE: Inheritance - placement practice test -Justin (10/20/15)
  • Question 15, the answer is wrong. Here is the example

    Class Base { Base(int i) {...}; };
    Class Derived: public Base { Derived() : Base {10} {};};

    Not practical in real world use, but true
  • RE: Inheritance - placement practice test -Amol Kothalkar (01/06/15)
  • This test is very much efficient to increase the knowledge for the interview point of view.