Multilevel Inheritance In C++

Share Your Love

Multilevel inheritance In C++ is the process of deriving a class from another derived class.

Multilevel Inheritance In C 1
Multilevel Inheritance

C++ Multi Level Inheritance Example:

In C++, multi-level inheritance occurs when one class inherits another class, which in turn inherits another class. Because inheritance is transitive, the last derived class inherits all of its base classes’ members.

Let’s look at a C++ example of multi-level inheritance.

#include <iostream>  
using namespace std;  
 class Animal {  
   public:  
 void eat() {   
    cout<<"Eating..."<<endl;   
 }    
   };  
   class Dog: public Animal   
   {    
       public:  
     void bark(){  
    cout<<"Barking..."<<endl;   
     }    
   };   
   class BabyDog: public Dog   
   {    
       public:  
     void weep() {  
    cout<<"Weeping...";   
     }    
   };   
int main(void) {  
    BabyDog d1;  
    d1.eat();  
    d1.bark();  
     d1.weep();  
     return 0;  
} 

Output:

Eating...
Barking...
Weeping...

Join Our Community

Join our WhatsApp Group To know more About Programming Language tips, tricks and knowledge about programming and how to start learning any programming language.

Share Your Love
Avatar photo
Lingaraj Senapati

Hey There! I am Lingaraj Senapati, the Founder of lingarajtechhub.com My skills are Freelance, Web Developer & Designer, Corporate Trainer, Digital Marketer & Youtuber.

Articles: 429

Newsletter Updates

Enter your email address below to subscribe to our newsletter