Skip to content

inheritance

In object-oriented programming (OOP), inheritance allows you to create a new class by inheriting features from an existing one. You can define a class that inherits data (attributes) and behavior (methods) from another class, known as the base class, superclass, or parent class.

This mechanism promotes code reuse and helps you create a hierarchical class structure that reflects real-world relationships. By using inheritance, you can override or extend the functionality of the parent class to tailor the behavior of the derived or child class to meet specific requirements.

Example

Here’s an example of inheritance in Python:

Language: Python
class Vehicle:
    def __init__(self, brand, model):
        self.brand = brand
        self.model = model

    def start_engine(self):
        print(f"The {self.brand} {self.model}'s engine is starting!")

class SelfDrivingCar(Vehicle):
    def self_drive(self):
        print("Self-driving through the road!")

# Usage
car = SelfDrivingCar("Waymo", "One")
car.start_engine()  # Output: The Waymo One's engine is starting!
car.self_drive()  # Output: Self-driving through the road!

In this example, the SelfDrivingCar class inherits from the Vehicle class. Apart from .brand, .model and .start_engine(), which are inherited members, the class implements the .self_drive() method to provide extended functionality.

Inheritance and Internals: Object-Oriented Programming in Python

Course

Inheritance and Internals: Object-Oriented Programming in Python

In this video course, you'll learn about the various types of inheritance that you can use to write object-oriented code in Python. These include class inheritance, multilevel inheritance, and multiple inheritance, along with special methods and abstract base classes.

intermediate python

For additional information on related topics, take a look at the following resources:

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Sept. 10, 2026