public class Occupant {
private Position pos;
public Occupant(Position iniPos) {
this.pos = iniPos;
}
public Position getPosition() {
return pos;
}
public void setPosition(Position newPos) {
this.pos = newPos;
}
public String getStringRepresentation() {
return " ";
}
}
我需要覆蓋getStringRepresenation在其子類X,這是我寫的。@Override表示法應該在哪裏?
public class Mine extends Occupant {
private Position pos;
public Mine(Position iniPos) {
this.pos = iniPos;
}
public String getStringRepresentation() {
return "X";
}
}
我不確定在哪裏使用super和@Override,該類將不會編譯。
它不會允許我通過公開Mine(位置iniPos){ this.pos = iniPos; } – user3413917
它在測試文件中有testMine = new Mine(position);我以爲多數民衆贊成我需要寫在班上 – user3413917
檢查我更新的答案 –