所以我有一个汽车班和一个汽车测试员班。这是汽车类:
package main;
public class Car {
private long distance;
private double newDistance;
private double gasAmount;
private double newGasAmount;
// Contrsuctor
Car(){
distance = 0;
}
Car(long newDistance){
distance = newDistance;
}
//Accessor
public long getDistance(){
return distance;
}
public double getGasInTank(){
return gasAmount;
}
//Mutator
public void drive(double distance){
newDistance = distance;
}
public void addGas(double gasAmount){
newGasAmount = gasAmount;
}
}
这就是问题所在。在我的 carTester 课程中,为什么myVehicle.drive();
不起作用?它用红色(netBeans)强调它并说“包myVehicle不存在”
package main;
public class CarTester {
Car myVehicle = new Car();
myVehicle.drive();
double gasLeft = myVehicle.getGasInTank();
}