Hybrid Inheritance is a combination of two types of inheritance namely the multiple and hierarchical Inheritance.


using namespace std;
class base1{ 
public: void msg1(){ 
cout<<"base1 - msg1"<<endl;
} }; 
class base2{ 
public: void msg2(){ 
cout<<"base2 - msg2"<<endl;
} }; 
class der1 : public base1{ 
public: void msg3(){ 
cout<<"der1 - msg3"<<endl; 
} };
class der2 : public der1, public base2{ public: void msg4()
{ cout<<"der2 - msg4"<<endl;
} }; int main(){ base1 b1; b1.msg1();
base2 b2; b2.msg2(); der1 d1; d1.msg1();
der2 d2;
return 0; }

Output:-base1 – msg1
base2 – msg2
base1 – msg1
der1 – msg3
base1 – msg1
base2 – msg2
der1 – msg3
der2 – msg4

Explanation of the program

In this program, base1 and base2 are the base classes. The class der1 is derived from base1 and class der2 is derived from base and der1.

This article is written by our awesome writer
Comments to: Simple Program For Hybrid Inheritance in C++

Your email address will not be published. Required fields are marked *

Attach images - Only PNG, JPG, JPEG and GIF are supported.

New Dark Mode Is Here

Sign In to access the new Dark Mode reading option.

Join our Newsletter

Get our monthly recap with the latest news, articles and resources.

By subscribing you agree to our Privacy Policy.

Latest Articles

Explore Tutorials By Categories


Codeverb is simply an all in one interactive learning portal, we regularly add new topics and keep improving the existing ones, if you have any suggestions, questions, bugs issue or any other queries you can simply reach us via the contact page


Welcome to Codeverb

Ready to learn something new?
Join Codeverb!

Read Smart, Save Time
    Strength indicator
    Log In | Lost Password