Hybrid inheritance in C++ language
In this tutorial, we will discuss the OOP concept of Hybrid inheritance in C++ language
Hybrid inheritance is a Oop concept of inheritance which one or more type of inheritance are combined together and use. it is a combination of Single level inheritance, Multilevel inheritance, and multiple inheritance
Java not supported the hybrid inheritance however using interfaces it is possible to make hybridinheritance as well as multiple inheritance in java
Syntex
Output
Explanation of above program
program 2
#include <iostream>
using namespace std;
int a,b,c,d,tot; // assign variables for int
class A{ //start class A
protected:
public:
void get_val_ab(){ //create method for get value of a,b
cout << “Enter a,b value” << endl;
cin >> a>>b;
}
}; //end class A
class B:public A{ // class B inherits properties from class A // start class B
protected:
public:
void get_val_c(){ //create method for get value of c
cout << “Enter c value” << endl;
cin >> c;
}
};
class C{ // start class C
protected:
public:
void get_val_d(){//create method for get value of d
cout << “Enter d value” << endl;
cin >> d;
}
}; // end class B
class D: public B,public C{ // start class D, class D inherits properties from class B,C
protected:
public:
void result(){
get_val_ab();
get_val_c();
get_val_d();
tot=a+b+c+d;
cout << “Addition is ” <<tot<<endl;
}
}; //end class D
int main()
{
D d1; //create object for class D
d1.result();
return 0;
}