Skip to content
uencoder

Inheritance

Inheritance lets a subclass reuse and extend its parent class's fields and methods, establishing an is-a relationship — a core mechanism of object orientation.

Purpose

Code reuse and hierarchical modeling, but overuse leads to the fragile base class problem.

Mechanism

A subclass inherits parent members and may add or override them. Single inheritance (Java classes) vs multiple inheritance (C++/Python). The diamond problem requires virtual inheritance (C++) or linearization (Python MRO). Composition over inheritance is the guiding principle.

Use cases

  • Object-oriented design
  • Hierarchical modeling
  • Code reuse

Related terms

References