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

Related Posts:

  • Components of Standered Template Library (STL) Components of Standered Template Library (STL) The STL contains several components but at its core are 3 key components:-     They are- 1. Container 2. Algorithm 3. Iterators -> The Relatonship between The 3… Read More
  • Containers and Applications of Container Classes in STL Containers:- Containers are objects that hold data. The STL defines Ten containers which are grouped into three categories. 1. Sequence Containers     Sequence containers store elements in a linear sequ… Read More
  • C++ Standered Template Library (STL) C++ Standered Template Library (STL) Template can be used to create generic classes and functions that could extend supports for Generic programming.     -> In order to help the C++ users in generic programming… Read More
  • C++ Program to demonstrate Multiple catch statements C++ Program to demonstrate Multiple catch statements #include<iostream> using namespace std; void test(int x) { try { if(x==1) throw x; else     if(x==0) throw 'x'; else     if(x==-1) t… Read More
  • C++ Stream classes Structure C++ Stream classes Structure -> The C++ I/O system contains a hierarchy of classes that are used to define various streams to deal with both the console and disk files, These classes are called Stream classes. -> Str… Read More

Translate

Popular Posts