//multiple inheritance
#include <iostream.h>
#include <conio.h>
class A
{
protected:
int a;
public:
A()
{
cout<<"constructor A executed"<<endl;
}
void input()
{
cout<<"enter a ";
cin>>a;
}
void output()
{
cout<<a<<endl;
}
};
class B
{
protected:
int b;
public:
B()
{
cout<<"constructor B executed"<<endl;
}
void get()
{
cout<<"enter b ";
cin>>b;
}
void show()
{
cout<<b<<endl;
}
};
class C:public A,public B //constructor A will be executed first then B then C and when A is replaced by B then B will be executed first
{
public:
C()
{
cout<<"constructor C executed"<<endl;
}
void inc()
{
b++;
cout<<"increament in b: "<<b<<endl;
}
};
void main()
{
C obj;
obj.input();
obj.output();
obj.get();
obj.show();
obj.inc();
getch();
}
#include <iostream.h>
#include <conio.h>
class A
{
protected:
int a;
public:
A()
{
cout<<"constructor A executed"<<endl;
}
void input()
{
cout<<"enter a ";
cin>>a;
}
void output()
{
cout<<a<<endl;
}
};
class B
{
protected:
int b;
public:
B()
{
cout<<"constructor B executed"<<endl;
}
void get()
{
cout<<"enter b ";
cin>>b;
}
void show()
{
cout<<b<<endl;
}
};
class C:public A,public B //constructor A will be executed first then B then C and when A is replaced by B then B will be executed first
{
public:
C()
{
cout<<"constructor C executed"<<endl;
}
void inc()
{
b++;
cout<<"increament in b: "<<b<<endl;
}
};
void main()
{
C obj;
obj.input();
obj.output();
obj.get();
obj.show();
obj.inc();
getch();
}
0 comments:
Post a Comment