Multiple Inheritance - OOP's Concept

What is Multiple Inheritance OOP's concept in C++?

Explanation

Multiple Inheritance is a method by which a class is derived from more than one base class.

Example :


#include <iostream.h> using namespace std; class Square
{
protected:
int l;
public:
void set_values (int x)
{ l=x;}
}; class CShow
{
public:
void show(int i);
};
void CShow::show (int i)
{
cout << "The area of the square is::" << i << endl;
}
class Area: public Square, public CShow
{
public:
int area()
{ return (l *l); }
}; int main ()
{
Area r;
r.set_values (5);
r.show(r.area());
return 0; }

Result :

The area of the square is:: 25

In the above example the derived class "Area" is derived from two base classes "Square" and "CShow". This is the multiple inheritance OOP's concept in C++.

C++ Tutorial


Ask Questions

Ask Question