Computer ScienceProgrammingMedium

Inheritance (OOP)

Also known as:subclassingclass extensionderivation

Inheritance is an OOP mechanism whereby a child class (subclass) automatically acquires the attributes and methods of a parent class (superclass), enabling hierarchical relationships between classes. The subclass can extend or override inherited behaviour without modifying the original parent class, promoting code reuse and reducing duplication. Inheritance models real-world "is-a" relationships, such as a Dog being an Animal.

Types of Inheritance in OOP

TypeDescriptionExampleSupported in Java?
SingleOne subclass inherits one superclassDog extends AnimalYes
MultilevelChain of inheritancePoodle extends Dog extends AnimalYes
HierarchicalMultiple subclasses, one superclassCat, Dog both extend AnimalYes
MultipleOne subclass, multiple superclassesFlyingFish extends Fish, BirdNo (via interfaces)
HybridCombination of above typesComplex class hierarchyNo (via interfaces)

Interactive Tools

Codecademy – Inheritance in Java

Open Tool

W3Schools – Python Inheritance

Open Tool

Brilliant – Inheritance

Open Tool
Diagram showing inheritance hierarchy from superclass to subclasses

Wikimedia Commons, CC BY-SA

Related Terms

Computer Science

Class (OOP)

A class in object-oriented programming is a blueprint or template that defines the attributes (data fields) and methods (functions) common to all objects of that type. When a class is instantiated, it produces an object — a concrete instance that holds its own copy of the class's attributes. Classes enable code organisation by grouping related data and behaviour together, forming the foundational building blocks of OOP design.

Computer Science

Polymorphism

Polymorphism is the OOP principle that allows a single interface or method name to represent different underlying implementations depending on the object type. There are two main forms: compile-time polymorphism (method overloading, where multiple methods share a name but differ in parameters) and runtime polymorphism (method overriding, where a subclass provides its own implementation of a parent's method). Polymorphism makes programs more flexible and extensible, allowing new object types to be added without changing existing code.

Computer Science

Object-Oriented Programming

Object-Oriented Programming (OOP) is a programming paradigm that organises software design around data, called objects, rather than functions and logic. Each object encapsulates data (attributes) and behaviour (methods), and objects interact with one another to build complex systems. The four core principles of OOP — encapsulation, inheritance, polymorphism, and abstraction — promote code reusability, modularity, and maintainability.

From Latin "inheritare" meaning to receive as an heir. In programming, the concept was formalised in Simula 67 by Dahl and Nygaard, where subclasses could extend superclasses. The term became widespread with C++ (1983) and Java (1995).

inheritanceoopsubclasssuperclasscode-reuse