我有这样的根目录:
├── classes
└── src
└── vehicles
├── Bicycle.java
└── BicycleMain.java
自行车.java
package vehicles;
public class Bicycle {
public int cadence;
public int gear;
public int speed;
public Bicycle(int startCadence, int startSpeed, int startGear) {
gear = startGear;
cadence = startCadence;
speed = startSpeed;
}
public void setCadence(int newValue) {
cadence = newValue;
}
public void setGear(int newValue) {
gear = newValue;
}
public void setSpeed(int newValue) {
speed = newValue;
}
public int getGear() {
return gear;
}
public int getCadence() {
return cadence;
}
public int getSpeed() {
return speed;
}
public void applyBrake(int decrement) {
speed -= decrement;
}
public void speedUp(int increment) {
speed += increment;
}
BicycleMain.java
package vehicles; import vehicles.*;
public class BicycleMain {
public static void main (String args[]){
Bicycle Bike = new Bicycle(10, 20, 1);
System.out.println("We have a new bicycle with speed = " +Bike.getSpeed()+", cadence = "+Bike.getCadence()+", gear = "+Bike.getGear());
} }
我编译了 Bicycle.java 并成功,但没有 BicycleMain.java :
symbol : class Bicycle
location: class vehicles.BicycleMain
Bicycle Bike = new Bicycle(10, 20, 1);
^
src/vehicles/BicycleMain.java:6: cannot find symbol
symbol : class Bicycle
location: class vehicles.BicycleMain
Bicycle Bike = new Bicycle(10, 20, 1);
^
2 errors
我尝试使用 Netbeans 运行这些文件,并且它可以正常工作!但是为什么当我在 CLI 中编译时它不起作用?