In the Hierarchical Inheritance, there is only base class and all the derived classes are derived from this base class. The following is the schematic representation.

Class A is the base class and class B and class C are the derived classes. Two classes are derived from the base class. Have a look at the following example.

Simple Example of Hierarchical Inheritance in C++ program

#include<iostream>
using namespace std;
class base{ public: void rbc1(){ 
  cout<<"base - rbc1"<<endl;
} }; class der1 : public base{ 
 public: void rbc2() { 
  cout<<"der1 - rbc2"<<endl;
} }; class der2 : public base{ 
 public: void rbc3()
{ cout<<"der2 - rbc3"<<endl;
} }; int main(){ 
base b; b.rbc1(); 
der1 d1; d1.rbc1();
d1.rbc2(); der2 d2; 
d2.rbc1();d2.rbc3();
return 0; }

Output:-base – rbc1
base – rbc1
der1 – rbc2
base – rbc1
der2 – rbc3

This article is written by our awesome writer
Comments to: Hierarchical 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

About

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

Login

Welcome to Codeverb

Ready to learn something new?
Join Codeverb!

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