Multiple Inheritance

Multiple Inheritance is a feature of C++ where a class can inherit from more than one classes. The constructors of inherited classes are called in the same order in which they are inherited.

Following is the code in c++ for understanding of multiple inheritance:

#include<iostream>
#include<conio.h>
using namespace std;
class A
{
int a;
public:

A()
{ a=0;}
A(int x)
{a=x;}
void show()
{ cout<<a; }
};
class B
{
int b;
public:
B()
{  b=0;}

B(int y)
{b=y;}
void show()
{cout<<b;}
};
class C:public A,public B
{
int c;
public:
C()
{
A:A();
B:B();
c=0;
}
C(int u,int v,int w)
{  c=w;}
void show()
{
A::show();
B::show();
cout<<c;
}
};
void main()
{
C obj(1,2,3);
obj.show();
getch();
}

Print Friendly

Share this with your friends

2 Comments to “Multiple Inheritance”

  1. Hats off to whevoer wrote this up and posted it.

    1. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *