# Types of Inheritance

> The types of inheritance are five structural arrangements of base and derived classes: single (one subclass, one superclass), multilevel (a chain of classes), hierarchical (many subclasses of one superclass), multiple (one subclass with several superclasses) and hybrid (a mix of these). C++ supports multiple inheritance of classes, while Java and C# allow it only through interfaces.

Canonical: https://devsunite.com/resources/core-subjects/oop/types-of-inheritance
Last updated: 2026-11-22

Subject: OOP · Category: Inheritance · 3 min read

Inheritance isn't just one shape. Depending on how classes are arranged relative to each other, it falls into one of five recognized categories.

## The five types

**Single inheritance**: one subclass inherits from exactly one superclass. This is the simplest and most common case.

```
Animal → Dog
```

**Multilevel inheritance**: a chain, where a subclass itself becomes the superclass for another class.

```
Animal → Mammal → Dog
```

**Hierarchical inheritance**: multiple subclasses inherit from the same single superclass.

```
        Animal
       /      \
     Dog      Cat
```

**Multiple inheritance**: one subclass inherits from more than one superclass at the same time. C++ supports this directly; Java and C# don't allow it for classes (only through interfaces), largely because of the ambiguity problems it can create.

```
Flyable    Swimmable
      \      /
        Duck
```

**Hybrid inheritance**: a combination of two or more of the above types in the same hierarchy, most commonly hierarchical mixed with multiple.

## A worked example

```cpp
#include <iostream>
using namespace std;

class Animal {
public:
    void eat() { cout << "This animal eats food." << endl; }
};

class Mammal : public Animal {       // multilevel: Mammal inherits Animal
public:
    void breathe() { cout << "This mammal breathes air." << endl; }
};

class Dog : public Mammal {          // Dog inherits Mammal, which inherited Animal
public:
    void bark() { cout << "Woof!" << endl; }
};

int main() {
    Dog d;
    d.eat();      // from Animal, two levels up
    d.breathe();  // from Mammal, one level up
    d.bark();     // Dog's own
    return 0;
}
```

`Dog` here demonstrates multilevel inheritance: it doesn't inherit from `Animal` directly, it inherits from `Mammal`, which inherits from `Animal`. All three levels' methods are available on a `Dog` object.

## Where this matters in real systems

Hierarchical inheritance is everywhere in UI toolkits: a single base `Shape` class might be the superclass for `Circle`, `Rectangle`, and `Triangle`, each specializing the same shared interface (like a `draw()` method) differently. Multiple inheritance through interfaces shows up constantly in Java: a class like `ArrayList` implements both `List` and `RandomAccess`, combining capabilities from two separate interface hierarchies without the ambiguity problems that multiple class inheritance can cause.

## What interviewers actually ask about types of inheritance

- **"Why doesn't Java support multiple inheritance of classes?"** To avoid the diamond problem, the ambiguity that arises when a class inherits the same member from two different paths. Java sidesteps it by only allowing multiple inheritance through interfaces, which don't carry implementation ambiguity in the same way.
- **"What's the difference between hierarchical and multilevel inheritance?"** Hierarchical is one superclass with multiple direct subclasses; multilevel is a chain where each class extends the one before it.
- **"Give an example of hybrid inheritance."** Any design mixing two shapes, for example a hierarchy where `Animal` has subclasses `Bird` and `Fish` (hierarchical), and `Bird` further has its own subclass `Penguin` (multilevel) layered on top.
- **"Does C++ allow multiple inheritance, and what's the risk?"** Yes, directly. The risk is the diamond problem when two base classes share a common ancestor, which is solved with virtual base classes.

## Key takeaways

- The five types are single, multilevel, hierarchical, multiple, and hybrid.
- Single: one base, one derived. Multilevel: a chain. Hierarchical: one base, many derived.
- Multiple: one derived class, several base classes at once, supported directly in C++ but only via interfaces in Java/C#.
- Hybrid combines two or more of the other types in one hierarchy.

## Related

- [Previous: Super and Sub Classes](https://devsunite.com/resources/core-subjects/oop/super-and-sub-classes)
- [Next: Access Specifiers in Inheritance](https://devsunite.com/resources/core-subjects/oop/access-specifiers-in-inheritance)
- [More in Inheritance: Overview of Inheritance](https://devsunite.com/resources/core-subjects/oop/overview-of-inheritance)
- [More in Inheritance: Constructor and Destructor Order in Inheritance](https://devsunite.com/resources/core-subjects/oop/constructor-and-destructor-in-inheritance)
- [More in Inheritance: Virtual Base Classes](https://devsunite.com/resources/core-subjects/oop/virtual-base-classes)
- [More in Inheritance: Composition vs Aggregation vs Inheritance](https://devsunite.com/resources/core-subjects/oop/composition-vs-aggregation-vs-inheritance)
- [All 72 OOP interview questions](https://devsunite.com/resources/core-subjects/oop)
