gpt4 book ai didi

java - 扩展类的 Eclipse 错误

转载 作者:行者123 更新时间:2023-11-29 05:46:48 26 4
gpt4 key购买 nike

我正在尝试从下面的一个创建和扩展类,但我从 eclipse 收到一条错误消息,说“ token “{”上的语法错误,{预期在此 token 之后”

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;

}

是否有更好的方法来设置具有相同变量和操作但具有不同值的“飞船”?

最佳答案

看起来您正在尝试为您的 Frigate 初始化实例变量。将该代码放在构造函数中。

public Frigate()
{
this.hull = 10;
this.shield = 10;
}

关于java - 扩展类的 Eclipse 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15579585/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com