ข้ามไปยังเนื้อหา
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

เอกสารประกอบการเรียน

เข้าสู่ระบบหรือสร้างบัญชี

IGCSE, A-Level & AP