Multiple Inheritance in C++ by R4R Team

What is Inheritance in C++ :
In C++,
-Inheritance is a process in which one object acquires all the properties and behaviors of its parent object automatically. In such way, you can reuse, extend or modify the attributes and behaviors which are defined in other class.

Type of Inheritance in C++:
-Single Inheritance
-Multiple Inheritance
-Multilevel Inheritance
-Hierarchical inheritance
-Hybrid inheritance

2.Multiple Inheritance:
-When child class inherite the property from multiple class then it is called Multiple Inheritance.
Syntax-
class one
{
};
class two
{
};
class three
{
};
class child:public one,public two, public three
{
};

program:

#include< iostream>
using namespace std;
class A
{
protected:
int a;
public:
void get_a(int n)
{
a = n;
}
};
class B
{
protected:
int b;
public:
void get_b(int n)
{
b = n;
}
};
class C : public A,public B
{
public:
void display()
{
cout << "The value of a is : " << a<< endl;
cout << "The value of b is : " << b<< endl;
cout<<"Addition of a and b is : "<< a+b;
}
};
int main()
{
C c;
c.get_a(10);
c.get_b(20);
c.display();
return 0;
}


output-

The value of a is : 10
The value of b is : 20
Addition of a and b is : 30




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!