0
當編譯下面的代碼時,得到下面的錯誤:CircleObject不是抽象並且在圖不重寫抽象方法
Abstrct.java:7: error: CircleObject is not abstract and does not override abstract method changePosition(int,int) in Figure
class CircleObject extends Figure
^
Abstrct.java:14: error: Kd is not abstract and does not override abstract method draw() in Figure
class Kd extends Figure
^
2 errors
使用
abstract class Figure {
int x, y;
abstract void changePosition(int newX, int newY);
abstract void draw();
}
class CircleObject extends Figure {
void draw() {
System.out.println("Draw method called");
}
}
class Kd extends Figure {
void changePosition(int newX, int newY) {
System.out.println("Change Position method called");
}
}
class Abstrct {
public static void main(String args[]) {
Figure q = new CircleObject();
q.draw();
Figure p = new Kd();
p.changePosition(2, 4);
}
}
'Circle'或者需要是'abstract'或者實現'changePosition'方法 – MadProgrammer