Skip to content

Single Inheritance

Single inheritance is when a child class inherits from exactly one parent class. It’s the simplest and most common form of inheritance.

All OOP languages support single inheritance.


AspectDescription
ParentsExactly one parent class
ChildrenOne or more children (each has one parent)
ComplexityLow — simple and clear hierarchy
Diamond ProblemNot possible
SupportEvery OOP language

class Animal {
constructor(name) {
this.name = name;
}
eat() {
console.log(`${this.name} is eating`);
}
sleep() {
console.log(`${this.name} is sleeping`);
}
}
class Dog extends Animal {
bark() {
console.log(`${this.name} barks!`);
}
}
const dog = new Dog("Rex");
dog.eat(); // "Rex is eating" (inherited)
dog.sleep(); // "Rex is sleeping" (inherited)
dog.bark(); // "Rex barks!" (own method)

classDiagram
class Animal {
+name: string
+eat() void
+sleep() void
}
class Dog {
+bark() void
}
Animal <|-- Dog : extends

Previous Topic: Types Overview → Next Topic: Multilevel Inheritance →