クラスの親子関係
クラス名 Ball
属性 x, y, color
メソッド move, reset
13
クラス名 Circle
属性 x, y, color, r
メソッド move, reset
クラス Circle は,親クラスで
あるクラス Ball の属性とメ
ソッドを継承する.
class Ball {
double x;
double y;
String color;
public Ball(double x, double y,
String color) {
this.x = x;
this.y = y;
this.color = color;
}
public void move(double xx, double
yy) {
this.x = this.x + xx;
this.y = this.y + yy;
}
public void reset() {
this.x = x;
this.y = y;
}
}
class Circle extends Ball {
double r;
public Circle(double x, double y, String color,
double r) {
super(x, y, color);
this.r = r;
}
}