C++ Multiple Inheritance
Multiple inheritance is such an inheritance in which a derived class inherits properties of more than one base class.
C++ Multiple Inheritance Example
In this example, two base classes Square and Show are inherited in one derived class Area.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include <iostream> using namespace std; class Square { protected: int l; public: void setvalues (int x){ l=x; } }; class Show{ public: void show(int i){ cout << "The area of the square is: " << i << endl; } }; class Area: public Square, public Show{ public: int area(){ return (l*l); } }; int main (){ Area a; a.setvalues (3); a.show(a.area()); return 0; } |
Output:
1 2 3 |
The area of the square is: 9 |