Skip to content · ⁨Bỏ qua nội dung⁩

Inheritance & encapsulation · ⁨Kế thừa & Bao封装⁩

English

Build on an existing class

  • Inheritance lets a new class reuse an existing one.
  • 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.)

Tiếng Việt

Xây dựng dựa trên một lớp có sẵn

  • Kế thừa cho phép một lớp mới tái sử dụng một lớp đã tồn tại.
  • Lớp mới là lớp con (con); lớp gốc là lớp cha (bố mẹ).
  • Viết class Bird(Animal): — Bird sẽ kế thừa tất cả các phương thức của Animal. (Trong伪代码 đề thi: CLASS Bird INHERITS Animal.)

Một Animal cha có describe(); Bird và Cow kế thừa nó, thêm hoặc ghi đè các phương thức

Handout · ⁨Tài liệu⁩

Log in or create account · ⁨Đăng nhập hoặc tạo tài khoản⁩

IGCSE, A-Level & AP