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

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.