Skip to content

Multilevel Inheritance

Multilevel inheritance is a chain of inheritance where class C inherits from class B, which inherits from class A. Each level in the chain adds more specific behavior.


AspectDescription
StructureGrandparent → Parent → Child
ComplexityMedium — must understand the full chain
RiskFragile base class problem
Depth LimitPractical limit: 3-5 levels

class Animal {
constructor(name) {
this.name = name;
}
eat() { console.log(`${this.name} is eating`); }
}
class Mammal extends Animal {
constructor(name, hasFur = true) {
super(name);
this.hasFur = hasFur;
}
breathe() { console.log(`${this.name} is breathing`); }
}
class Dog extends Mammal {
constructor(name, breed) {
super(name);
this.breed = breed;
}
bark() { console.log(`${this.name} barks!`); }
}
const dog = new Dog("Rex", "Labrador");
dog.eat(); // Inherited from Animal
dog.breathe(); // Inherited from Mammal
dog.bark(); // Own method

classDiagram
class Animal {
+eat() void
}
class Mammal {
+breathe() void
}
class Dog {
+bark() void
}
Animal <|-- Mammal : extends
Mammal <|-- Dog : extends

Previous Topic: Single Inheritance → Next Topic: Hierarchical Inheritance →