I have some Java code:
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;
}
}
I try to compile and run this specific program and I get this error:
CarClient.java:16: error: cannot find symbol
myCar.accelerateSpeed(speed);
^
symbol: variable speed
location: class CarClient
What does error: cannot find symbol mean?
You’re calling
accelerateSpeed(speed)but the only method you have implemented isaccelerate()which takes no parameters. Similarly, you’re trying to callbrakeSpeed(speed)but have only implementedbrake()with no parameters. Either implement the functions you’re trying to call, or change the names of the functions you already have implemented.