Categories: C++Learn C++

Hybrid inheritance in C++ language

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

Syntax
Hybrid inheritance flowdiagram
Diagram

 

Example

Output

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;
}

Example

 

Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.