Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/myscript/public_html/classes/classdb.php on line 42
Multiple Inheritance - C++ OOP's Tutorial

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