Inheritance

Inheritance lets one class (the child) reuse and extend the properties and methods of another class (the parent), avoiding repeated code.

General Programming

A child class automatically gets everything the parent has and can add or override behaviour. For example, a Dog class might inherit from a general Animal class.

Examples

Python

class Animal:
    def speak(self):
        return "..."

class Dog(Animal):
    def speak(self):
        return "Woof"

print(Dog().speak())

Output:

Woof

Learn it in a lesson

See also

Back to the Dictionary