extends
例子:
DrawDot dd1 = new DrawDot(50, 80);
void setup() {
size(200, 200);
}
void draw() {
dd1.display();
}
class Dot {
int xpos, ypos;
}
class DrawDot extends Dot {
DrawDot(int x, int y) {
xpos = x;
ypos = y;
}
void display() {
ellipse(xpos, ypos, 200, 200);
}
}
描述:允许新类从现有类继承方法和数据字段(变量和常量)。 在代码中,声明新类的名称,后跟关键字extends和基类的名称。 继承的概念是面向对象编程的基本原理之一。
请注意,在Java中,因此也是Processing,您不能多次扩展类。
- 本文固定链接: http://iprocessing.cn/2017/06/30/extends-继承/
- 转载请注明: 卡萨布兰卡 于 Processing编程艺术 发表