Loading....
Coupon Accepted Successfully!

 

Hybrid Inheritance

A combination of one or more types of inheritance is known as hybrid inheritance. Sometimes, it is essential to derive a class using more types of inheritance. Figure: Hybrid inheritance shows hybrid inheritance. In the below given diagram, the class game is derived from two base classes, that is, location and physique. The class physique is also derived from the class player.


Fig: Hybrid inheritance


11.10 Write a program to create a derived class from multiple base classes.

 

OUTPUT
Enter Following Information
Name : Mahesh
Gender : M
Age : 25
Height : 4.9
Weight : 55
City : Nanded
Pincode : 431603
Game : Cricket
Entered Information
Name : Mahesh
Gender : M
Age : 25
Height : 4.9
Weight : 55
City : Nanded
Pincode : 431603
Game : Cricket
 
Explanation: In the above program, player, physique, location, and game classes are defined. All the data members of these four classes are protected. The class physique is derived from the base class player. The class game is derived from physique and location; that is, the derived class game has two base classes physique and location. The location is a separate class and is not derived from any other class. The getdata() and show() are functions of class game and reads and display data, respectivelyIn main(), the object G of class game calls these functions one by one to read and write the data. The output of the program is shown at the end of the above program.





Test Your Skills Now!
Take a Quiz now
Reviewer Name