Repaso
Español

What is polymorphism?

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

Options

  1. A class that has many attributes and many methods inside
  2. The same call works on different types, each running its own code (Correct option)
  3. Changing the type of a variable while the program runs
  4. Copying one method into many classes of the same program

Answer

The same call (shape.area()) works on different types, each running its own version

Why

Polymorphism means 'many forms': different classes offer the same method name, and the caller does not need to know which class it has.

The loop calls area() on each shape; Circle and Square each compute it their own way.

This removes long if/elif chains that check the type.

Remember

Same method name, different behavior per class.

Key terms

Practice this question in Repaso