Loading....
Coupon Accepted Successfully!

 

Multilevel Inheritance

The procedure of deriving a class from a derived class is called multilevel inheritance.

In the above figure,
class A3 is derived from class A2. The class A2 is derived from class A1. The class A3 is a derived class. The class A2 is a derived class as well as a base class for class A3. The class A2 is called an intermediate base class. The class A1 is a base class of classes A2 and A3. The series of classes A1, A2, and A3 is called an inheritance pathway, as shown in Figure: Multilevel inheritance.
 

Fig: Multilevel inheritance
 

11.7 Write a program to create multilevel inheritance. Create classes A1, A2, and A3.

 

 

OUTPUT

Name : Balaji
Age : 26
Sex : M
Height : 4
Weight : 49.5
Name : Balaji
Age : 26 Years
Sex : M
Height : 4 Feets
Weight : 49.5 Kg.
 
Explanation: In the above program, the classes A1, A2, and A3 are declared. The member variables of all these classes are protected. The class A2 is derived from class A1. The class A3 is derived from class A2. Thus, the class A2 acts as a derived class as well as a base class. The function get() reads data through the keyboard, and the function show() displays data on the screen. Both the functions are invoked using object x of class A3.





Test Your Skills Now!
Take a Quiz now
Reviewer Name