A class can be derived by inheriting the traits of two or more base classes. Multiple inheritance refers to the derivation of a class from several i.e., two or more base classes. It allows the combination of the features of several existing, tested, and well proven classes as a starting point for defining new classes. Multiple inheritance model is as follows:
Sample Program
#include <iostream.h>
class ac
{
protected:
int cno;
char *name;
float amt;
public:
void newac(void)
{
cout<<”Enter the a/c number”;
cin>>cno;
cout<<”Enter the a/c name”;
cin>>name;
cout<<”Enter the initial amount”;
cin>>amt;
}
};
class dep
{
protected:
int dep;
public:
void depamt(void)
{
cout<<”Deposit amount is”<<dep;
}
};
class bank:public ac, public dep
{
float tot;
public:
void process(void)
{
newac();
depamt();
tot = amt + dep;
}
void showac(void)
{
cout<<”Number is “<<cno<<endl;
cout<<”Name is”<<name<<endl;
cout<<”Amount is”<<tot<<endl;
}
};
void main()
{
bank B;
B.process();
B.showac();
}
nice job
ReplyDelete