ข้ามไปยังเนื้อหา

Build on an existing class

  • Inheritance ช่วยให้คลาสใหม่สามารถนำคลาสเดิมมาใช้อีกครั้งได้
  • The new class is the subclass (child); the original is the superclass (parent)
  • Write class Bird(Animal): — Bird gets all of Animal's methods. (In exam pseudocode: CLASS Bird INHERITS Animal.)

Animal เป็นคลาสแม่ที่มีdescribe(); Bird และ Cow สืบทอดมา โดยเพิ่มหรือแทนที่เมทโธด

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

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

IGCSE, A-Level & AP