Software development · JavaScript and TypeScript

Inheritance

In Spanish: Herencia
See in the galaxyCopy link
Updated: 09/11/2026Reading: 2 min

Description

Inheritance in programming refers to the ability of a class to inherit properties and methods from another class. This concept is fundamental in object-oriented programming (OOP), where the aim is to promote code reuse and the creation of class hierarchies. Inheritance allows a derived class (or subclass) to acquire characteristics from a base class (or superclass), facilitating the extension and modification of behaviors without the need to rewrite existing code. There are different types of inheritance, such as single inheritance, where a class inherits from a single base class, and multiple inheritance, where a class can inherit from multiple classes. Inheritance can also be used to implement polymorphism, allowing different classes to respond to the same method call in a specific way. This concept is key to the organization and structuring of code, promoting a cleaner and more maintainable design.

History

Inheritance as a concept in programming originated with the development of object-oriented programming in the 1960s, with languages such as Simula, which introduced the idea of classes and objects. Over the years, inheritance has evolved and has been integrated into many modern programming languages, such as Java, C++, and Python, each with its own implementations and rules on how inheritance can be used.

Uses

Inheritance is used primarily in object-oriented programming to create class hierarchies that facilitate code reuse and the extension of functionality. It allows developers to create more specific classes based on general classes, which simplifies code maintenance and comprehension. It is also used in design patterns such as the Strategy pattern and the Observer pattern.

Examples

An example of inheritance is an 'Animal' class that has properties such as 'name' and 'age', and methods such as 'makeSound()'. Then, a 'Dog' class can be created that inherits from 'Animal' and adds specific properties such as 'breed' and a 'bark()' method. Another example is in web development frameworks, where models can inherit from base classes to share common fields and behaviors.

Glosarix on your device

Install
×
Enable Notifications Ok No