我有一些 Java 代码:
public class Car
{
private int yearModel;
private String make;
private int speed;
public Car(int newYearModel, String newMake)
{
yearModel = newYearModel;
make = newMake;
speed = 0;
}
public int getSpeed()
{
return speed;
}
public void accelerate()
{
speed += 5;
}
}
我尝试编译并运行这个特定的程序,但收到此错误:
CarClient.java:16: error: cannot find symbol
myCar.accelerateSpeed(speed);
^
symbol: variable speed
location: class CarClient
错误:找不到符号
是什么意思?
最佳答案
您正在调用 accelerateSpeed(speed)
,但您实现的唯一方法是 accelerate()
,它不带任何参数。同样,您尝试调用 brakeSpeed(speed)
,但仅实现了不带参数的 brake()
。要么实现您尝试调用的函数,要么更改您已实现的函数的名称。
关于java - 编译我的代码时找不到符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9270622/