C++ language

Multiple Inheritance
Previous Home Next

Program For Multiple Inheritance

#include<stdio.h>
class A
{
int a1,a2;
public :
void getdata()
{
cout<<"\n Enter value of a1 and a2";
cin>>a1>>a2;
}
void putdata()
{
cout<<"\n value of a1 is" <<a1"and a2 is"<<a2;
}
};
class B
{
int b1,b2;
public :
void indata()
{
cout<<"\n Enter the value of b1 nad b2";
cin>>b1>>b2;
}
void outdata()
{
cout<<"\n the value of b1 is" <<b1 "and b2 is:<<b2;
}
};
class C: public A,public B
{
int c1,c2;
public 
void input()
{
cout<<"\n enter the  value of c1 and c2";
cin>>c1>>c2;
}
void output()
{
cout<<"\nvalue of c1 is"<<c1"and c2 is"<<c2;
}
};
void main()
{
C c
c.getdata(); //member function of class A
c.indata();   //member function of class B
c.input();   //member function of class C
c.putdata();   //member function of class A
c.outdata();   //member function of class B
c.output();   //member function of class C
}

Output:

Enter the value of a1 and a2
5
4
Enter the value of b1 and b2
8
7
enter the value of c1 and c1
9
3
The value of a1 is 5 and a2 is 4
The value of b1 is 8 and b2 is 7
The value of c1 is 9 and c2 is 3
Previous Home Next