Multiple Inheritance in C++
In C++ programming, a class can be derived from more than one parents. For example: A classRectangle is derived from base classes Area and Circle.
Source Code to Implement Multiple Inheritance in C++ Programming
#include
#include
class first
{
int a;
public:
void get()
{
cin>>a;}
int disp()
{return a;}
};
class second
{
int b;
public:
void getsec(){
cin>>b;
}
int dispsec()
{
return b;}
};
class third:public first,public second
{
public:
void getfinal()
{
get();
getsec();
}
void dispfinal()
{
cout<<"ans="<<disp()+dispsec();
}
};
main()
{
third t1;
t1.getfinal();
t1.dispfinal();
getch();
}
0 comments:
Post a Comment