Skip to content

Writing a class: fields, constructor, methods · ⁨编写类:字段、构造方法和方法⁩

English

Make your own type

  • So far you used classes like String and Math that Java gave you.
  • Now you will write your own class. A class is a plan for an object.
  • An object holds data (its own values) and methods (things it can do).

中文

创建你自己的类型

  • 到目前为止,你用过 Java 提供的类,比如 String 和 Math。
  • 现在你要写自己的类(class)。类是对象的蓝图。
  • 一个对象保存数据(它自己的值)和方法(它能做的事)。

Dog 类是一张蓝图;由它造出两个新的 Dog 对象

Handout

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

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