Coupon Accepted Successfully!


Multiple Inheritance

Multiple inheritance is a latest addition to the C++ language. When a class is derived from more than one class, this type of inheritance is called multiple inheritance. A class can be derived by inheriting the properties of more than one class. Properties of various pre-defined classes are transferred to a single derived class. Figure: Multiple inheritance shows multiple inheritance.
Fig : Multiple Inheritance

11.8 Write a program to derive a class from multiple base classes.

Enter values of a,b,c & d & e : 1 2 4 8 16
a=1 b = 2 c = 4 d= 8 z= 16
Explanation: In the above program, classes A, B, C, D, and E are declared with a one-integer member variable each. The class E has a two-member function getdata() and showdata(), respectively. The getdata() is used to read integers through the keyboard, and showdata() is used to display the contents on the screen. The class E is derived from the classes A, B, C, and D. The classes A, B, C, and D act as a base class. The derivation is carried out with the statement class E: public A, B, C, and D. The class members of A are publicly derived, and the members of other classes are privately derived. To derive all class members publicly, they would be as class Z: public A, public B, public C, and public D. Remember, the meaning of both the statements is not same. Most programmers refer to the second format, as it reduces the code. The output of the program is as given above.

Test Your Skills Now!
Take a Quiz now
Reviewer Name