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

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

3 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

3 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

4 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

4 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

4 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

4 months ago

This website uses cookies.