我有个问题,我写了2个java文件,源文件如下:
一,vehicle.java:
public class vehicle{ public float journey; public int wheelNum; public int loadNum; public int driveSpeed; public vehicle(){ journey=100f; wheelNum=4; loadNum=1; } public void driveAt(int speed){ if(speed>=60){ System.out.println("行车速度太快,容易造成事故"); driveSpeed=40; } else{ System.out.println("你在安全行使速度内行使"); driveSpeed=speed;} } }
第二个是vehicleDriver.java:
public class vehicleDriver{ public String name; public vehicleDriver(){ name="TOM";} public void work(){ vehicle v=new vehicle(); v.driveAt(45);} public static void main(String arr[]){ vehicleDriver vd=new vehicleDriver(); vd.work();} }
第二个文件把第一个类实例化并调用他的方法,我很是奇怪,当我编译完vehicle.java的时候,产生了vehicle.class文件;可当我编译vehicleDriver.java文件的时候,却总是不成功。并且提示我以下内容: vehicleDriver.java :6: cannot resolve symbol symbol 1: class vehicle location: class vehicleDriver vehicle v=new vehicle(); symbol 1: class vehicle location: class vehicleDriver vehicle v=new vehicle(); 2 errors
而我把两个java文件用javac *.java同时编译的时候,却成功的产生两个类文件。为什么我不能分别对两个文件编译呢?每次编译vehicleDriver.java的时候都出现上面提示的错误,这是为什么?