1. Which among the following is best to define hierarchical inheritance?
a) More than one class is derived from one class
b) More than 2 classes being derived from the single base class
c) At most 2 classes being derived from the single base class
d) At most 1 class derived from another class
Answer:
a) More than one class is derived from one class
Explanation:
Hierarchical inheritance is a term used to describe the process by which two or more classes are derived from a single base class. This provides us the opportunity to use the same code in different contexts and with different levels of flexibility in different classes.
2. How many classes must be there to implement hierarchical inheritance?
a) Exactly 3
b) At least 3
c) At most 3
d) At least 1
Answer:
b) At least 3
Explanation:
There must be a minimum of three classes present. A total of three derived classes and one base class are present. This enables us to create two classes that share attributes with their base class counterparts.
3. How many classes can be derived from the base class using hierarchical inheritance?
a) As many as required
b) Only 7
c) Only 3
d) Up to 127
Answer:
a) As many as required
Explanation:
In addition, there are no restrictions on the number of classes that can be descended from a base class, which means that you will be able to derive as many classes as you require. This feature increases code reusability and flexibility by allowing for more code reuse.
4. Hierarchical inheritance can be a subset of _________________
a) Hybrid inheritance
b) Multiple inheritances
c) Single level inheritance
d) Multilevel inheritance
Answer:
a) Hybrid inheritance
Explanation:
Any form of inheritance or combination of inheritance, as well as more than two types, can be included in a hybrid inheritance structure. As a result, it may include Hierarchical inheritance as well, making it a subset of hybrid inheritance as well.
5. All the derived classes can access only a few members of the base class that other derived classes can’t access at the same time, in hierarchical inheritance.
a) True
b) False
Answer:
b) False
Explanation:
A full set of access to all non-private members of a base class is granted to derived classes. All members of the base class are accessible to all derived classes, and none of the derived classes can have special access to specific members of the base class in general.
Read more: Which of the following cannot be a structure member