12 Sept 2019

  • September 12, 2019
  • Amitraj
2.) multiple inheritance

Multiple inheritance occurs when a class inherits from more than one base class. So the class can inherit features from multiple base classes using multiple inheritance. This is an important feature of object oriented programming languages such as C++.
http://codevidyalay.blogspot.com

*A diagram that demonstrates multiple inheritance is given below −


// cpp program to demonstrate multiple inheritance.


#include<iostream>


using namespace std;


class Emp

{

protected:

int eno;

float sal;

public:

void getdata()
{
cout<<"Enter employee no:";
cin>>eno;
cout<<"Enter emp. salary:";
cin>>sal;
}
};
class Dept
{
protected:
char dname[20];
char location[20];
public:
void setdata()
{
cout<<"Enter department name:";
cin>>dname;
cout<<"Enter location:";
cin>>location;
}
};
class  Details :public Emp, public Dept
{
int exp;
public:
void get()
{
getdata();
setdata();
cout<<"Enter experience:";
cin>>exp;
}
void show()
{
cout<<"eno="<<eno<<" "<<sal<<" "<<dname<<" "<<location<<" "<<exp;
}
};

int main()
{
Details d;
d.get();
d.show();
return 0;
}

input/output:-

Enter employee no:11
Enter emp. salary:10000
Enter department name:IT
Enter location:jaipur
Enter experience:4

eno=11  10000  IT  jaipur  4


Translate

Popular Posts