Types of Inheritance
Types of Inheritance
Section titled “Types of Inheritance”Introduction
Section titled “Introduction”Inheritance can be categorized into different types based on how many parent and child classes are involved. Understanding these types helps you design class hierarchies effectively.
Types Overview
Section titled “Types Overview”graph TD Types["Types of Inheritance"] Types --> Single["Single Inheritance<br/>One parent, One child"] Types --> MultiLevel["Multilevel Inheritance<br/>Chain: A → B → C"] Types --> Hierarchical["Hierarchical Inheritance<br/>One parent, Many children"] Types --> Multiple["Multiple Inheritance<br/>Many parents, One child"] Types --> Hybrid["Hybrid Inheritance<br/>Combination of types"]
Single --> S1["✅ All OOP languages"] MultiLevel --> M1["✅ All OOP languages"] Hierarchical --> H1["✅ All OOP languages"] Multiple --> M2["⚠️ Python, C++ only<br/>Not in Java, JS, C#"] Hybrid --> H2["⚠️ C++ only"]1. Single Inheritance
Section titled “1. Single Inheritance”One child class inherits from one parent class.
class Parent { /* ... */ }class Child extends Parent { /* ... */ }Supported by: All OOP languages (JavaScript, TypeScript, Python, Java, C#)
2. Multilevel Inheritance
Section titled “2. Multilevel Inheritance”A chain of inheritance where class C inherits from class B, which inherits from class A.
class Animal { /* ... */ }class Mammal extends Animal { /* ... */ }class Dog extends Mammal { /* ... */ }Supported by: All OOP languages
3. Hierarchical Inheritance
Section titled “3. Hierarchical Inheritance”One parent class has multiple child classes.
class Animal { /* ... */ }class Dog extends Animal { /* ... */ }class Cat extends Animal { /* ... */ }class Bird extends Animal { /* ... */ }Supported by: All OOP languages
4. Multiple Inheritance
Section titled “4. Multiple Inheritance”One child class inherits from multiple parent classes.
// Not supported in JavaScript, TypeScript, Java, C#// Supported in Python, C++class Child extends Parent1, Parent2 { /* ... */ }Supported by: Python, C++ (not Java, JS, C#)
5. Hybrid Inheritance
Section titled “5. Hybrid Inheritance”A combination of multiple inheritance types — can lead to the diamond problem.
Supported by: C++ (rarely used)
Which Type Should You Use?
Section titled “Which Type Should You Use?”| Type | Use Case |
|---|---|
| Single | Most common — simple IS-A relationship |
| Multilevel | When each level adds more specificity |
| Hierarchical | When one concept has multiple variations |
| Multiple | When a class needs capabilities from multiple sources (use interfaces instead) |
| Hybrid | Avoid if possible — too complex |
Previous Topic: Inheritance Overview → Next Topic: Single Inheritance →