Skip to content

Polymorphism: dynamic dispatch and toString()

Handout

Polymorphism: one type, many behaviours

  • Polymorphism means "many forms": one superclass type, many subclass behaviours.
  • You can hold a Dog or a Cat in an Animal variable, because each is-an Animal.
  • When you call a method, the object's real type decides which version runs.

One call a.speak() gives Woof, Meow or Moo depending on the object's real type

Handout

Log in or create account

IGCSE & A-Level