C++ Multilevel Inheritance

🧬 C++ Multilevel Inheritance
Multilevel inheritance is a type of inheritance. In this case, a class comes from another derived class. This creates a chain of inheritance.
👉 Grandparent → Parent → Child
🔹 1. Basic Syntax
🔹 2. Simple Example
🔹 3. Constructor Call Order
In multilevel inheritance, constructors are called from base to derived.
Output:
🔹 4. Destructor Call Order
Destructors are called in reverse order.
🔹 5. Access Specifiers in Multilevel Inheritance
✔ protected members are accessible down the inheritance chain
❌ private members are not inherited
🔹 6. Method Overriding in Multilevel Inheritance
✔ Runtime polymorphism works across multiple levels
🔹 7. Real-Life Example
Vehicle: start(), stop()
Car: gear(), fuel()
ElectricCar: battery()
🔹 8. Advantages
Strong code reuse
Logical hierarchy
Easier maintenance
🔹 9. Disadvantages
Tight coupling
Changes in base affect all derived classes
Can become complex if deep
❌ Common Mistakes
➡ Restricts access unintentionally.
📌 Summary
Multilevel inheritance forms a chain of classes
Constructors: base → derived
Destructors: derived → base
Supports method overriding & polymorphism
Use
virtualfor runtime binding
