MCQ - Inheritance in C++ Programming
21. State whether the following statements about inheritance are True or False.
i) A public member of a class can be accessed by its own objects using the dot operator.
ii) While inheriting, the private members of the base class will never become the members of its derived class.
A. True, False
B. False, True
C. True, True
D. False, False
View Answer
Ans : C
Explanation: None.
22. In inheritance, order of execution of base class and derived class destructors are:
A. Base to derived
B. Derived to base
C. Random order
D. None of the above
View Answer
Ans : D
Explanation: In inheritance, execution order of constructors are always from base to derived and destructors call order is in reverse i.e. from derived to base. In polymorphic classes, means the class that contain virtual functions, we need to make destructor virtual in base class. Other wise the derived class destructor will not be called
23. What is the 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
Ans : B
Explanation: Protected member is inheritable and also accessible in derived class is the difference between protected and private access specifiers in inheritance.
24. Which value is placed in the base class?
A. Derived values
B. Default type values
C. Both A & B
D. None of the mentioned
View Answer
Ans : B
Explanation: We can place the default type values in a base class and overriding some of them through derivation.
25. The friend functions and the member functions of a friend class can directly access the______________ data.
A. Private and protected
B. Private and public
C. Protected and public
D. Private, protected and public
View Answer
Ans : A
Explanation: the friend functions and the member functions of a friend class can directly access the Private and protected data
26. What will be the order of execution of base class constructors in the following method of inheritance. class a: public b, virtual public c {...};
A. b(); c(); a();
B. c(); b(); a();
C. a(); b(); c();
D. b(); a(); c();
View Answer
Ans : B
Explanation: c(); b(); a(); will be the order of execution of base class constructors in the following method of inheritance. class a: public b, virtual public c {...};
27. 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
Ans : C
Explanation: None
28. Reusability of the code can be achieved in CPP through ______ .
A. Polymorphism
B. Encapsulation
C. Inheritance
D. Both A and C
View Answer
Ans : C
Explanation: None
29. Private members of the class are not inheritable.
A. TRUE
B. FALSE
C. May Be
D. Can't Say
View Answer
Ans : B
Explanation: None
Also check :
Discussion