Pular para o conteúdo

Polymorphism: dynamic dispatch and toString()

English

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.

The same call a.speak() gives Woof for a Dog, Meow for a Cat and Moo for a Cow

Material de apoio

Entrar ou criar conta

IGCSE, A-Level & AP