有人可以告诉为什么getSpeed方法不起作用吗?
每当我将鼠标悬停在方法上时,我都会得到:
插入;
非法修饰语
语法错误请插入[]
令牌
for
答案 0 :(得分:4)
您的main
方法包含以下方法。
public double getSpeed() {
return Speed;
}
请将此移至Tanks
课程。
以下应该工作:
public class Tanks {
private String TankName;
private int TankModel;
private int CrewNumber;
private double Speed;
private int TurretSpeed;
Tanks(String name, int model, int crew, double speed, int turretspeed) {
this.TankName = name;
this.TankModel = model;
this.CrewNumber = crew;
this.Speed = speed;
this.TurretSpeed = turretspeed;
}
public double getSpeed() {
return Speed;
}
public static void main(String[] args) {
Tanks merkava = new Tanks("MERKAVA", 1, 5, 56.64, 67);
Tanks judge = new Tanks("JUDGE", 2, 6, 66.66, 68);
System.out.println(merkava.TankName + " " + merkava.TankModel + " " + merkava.CrewNumber + " " + merkava.Speed
+ " " + merkava.TurretSpeed);
System.out.println(judge.TankName + " " + judge.TankModel + " " + judge.CrewNumber + " " + judge.Speed + " "
+ judge.TurretSpeed);
}
}
答案 1 :(得分:1)
如果您已经完成了一些基本的Java
课程,您将会知道通过在另一个函数(getSpeed()
)中定义一个方法(在本例中为main
)是错误的。