1
我試圖從一個波紋管創建和擴展類,但我發現從日食說{「令牌語法錯誤‘的錯誤消息的Eclipse錯誤用於擴展類
’,{此令牌後,預計」import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Vector2;
public class Ship {
protected int hull;
protected int shield;
protected Vector2 velocity;
protected int energy;
protected Texture shipTexture;
protected Vector2 position;
public Texture getShipTexture() {
return shipTexture;
}
public void setShipTexture(Texture shipTexture) {
this.shipTexture = shipTexture;
}
public Vector2 getPosition() {
return position;
}
public void setPosition(Vector2 position) {
this.position = position;
}
public int getHull() {
return hull;
}
public void setHull(int hull) {
this.hull = hull;
}
public int getShield() {
return shield;
}
public void setShield(int shield) {
this.shield = shield;
}
public Vector2 getVelocity() {
return velocity;
}
public void setVelocity(Vector2 velocity) {
this.velocity = velocity;
}
public int getEnergy() {
return energy;
}
public void setEnergy(int energy) {
this.energy = energy;
}
}
第一個括號之後這個類:
public class Frigate extends Ship {
this.hull = 10;
this.shield = 10;
}
有沒有更好的方式來設立「船」具有相同的變量和行動,但使用不同的值?
這看起來是一個很好的解決方案。有沒有簡單的方法來解釋爲什麼它需要構造函數來更改這些變量? – Bryan 2013-03-22 20:56:58
像'this.hull = 10;'這樣的東西是語句,而不是聲明。語句需要大量代碼,例如構造函數和方法。 – rgettman 2013-03-22 20:59:01
好的。感謝信息rgetttman。 – Bryan 2013-03-22 21:01:14