polymorphism

One call behaving differently depending on the class of the object it is made on.

In more detail

When a parent's method calls self.area(), self is the actual object, so a subclass's override of area runs. Different classes can therefore answer the same call in their own way without the caller knowing which class it holds. Overriding a method in a subclass is how Python achieves it.

Example

for shape in (Square(3), Circle(2)):
    print(shape.area())

Related terms

Taught in

References

Certification courses