Skip to content

Inheritance & encapsulation · ⁨继承与封装⁩

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.)

中文

在已有的类上扩展

  • 继承(inheritance)让一个新类复用一个已有的类。
  • 新类是子类(subclass);原来的类是父类(superclass)。
  • 写 class Bird(Animal): —— Bird 会获得 Animal 的所有方法。(考试伪代码里写作 CLASS Bird INHERITS Animal。)

Animal 父类有 describe();Bird 和 Cow 继承它,各自新增或重写方法

Handout

Log in or create account · ⁨登录或创建账户⁩

IGCSE, A-Level · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩