无法弄清楚为什么我会收到此错误。在记事本中工作,通过 cmd 运行 javac(显然更多的是文件)。如果您需要我链接更多,我可以。我的错误发生在“setCruiseShip”,我试图将当前链接到超类。错误:对 super 的调用必须是构造函数中的第一条语句。
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";}
}