第一條語句不能找出爲什麼我得到這個錯誤。在記事本中工作,通過cmd運行javac(顯然更多的是文件)。如果你需要我連接更多我可以。 我的錯誤發生在「setCruiseShip」,我試圖將當前連接到超類。 錯誤:調用超級必須是構造函數中的第一條語句。錯誤:超級必須在構造函數
class Ship
{ protected String name;
protected float speed;
protected int year;
public Ship() {name=""; speed=year=0;}
public Ship(String n, float sp, int y) {name=n; speed=sp; year=y;}
public String getName() {return name;}
public float getSpeed() {return speed;}
public int getYear() {return year;}
public void setShip(String n, float sp, int y) {name=n; speed=sp; year=y;}
public String toString() {return "Ship named "+name+ " with max speed of "
+speed+ " was built in " +year;}
}
class CruiseShip extends Ship
{ protected int maxpass;
public CruiseShip() {super(); maxpass=0;}
public CruiseShip(String n, float sp, int y, int mp) {super(n, sp, y);
maxpass=mp;}
public int setMaxpass(int mp) {maxpass=mp;}
public void setCruiseShip(String n, float sp, int y, int mp){super(n,sp,y);
maxxpass=mp;}
public String toString() { return super.toString() +" carries "
+maxpass+ " passengers";}
}
使用單獨的.java文件相同,也使公衆班班。 – codeMan 2013-03-11 08:49:14
'setCruiseShip'不是構造函數,所以它不能調用'super'構造函數。 – 2013-03-11 08:49:20