Search code examples
javainterfacepackage

file name "Car.java" this class is not compiling and showing error


"Vehicle.java" this class is compiling and creating a package vehicles

package vehicles;
interface Vehicle {
    public void run();
    public void speed();
}

"Car.java"

package vehicles;
public class Car implements Vehicle
{
        public void run()
        {
                System.out.println("Car is running.");
        }
        public void speed()
        {
                System.out.println("Speed of Car: 50 Km/h");
        }
        public static void main(String args[])
        {
                Car Car = new Car();
                Car.run();
                Car.speed();
                System.out.println("Hello World!");
        }
}

is not compiling and showing error

PS D:\Programming\java2> javac -d . Car.java
Car.java:2: error: cannot find symbol
public class Car implements Vehicle
                            ^
symbol: class Vehicle
1 error

Why am I getting this error?


Solution

  • Do Car.java and Vehicle.java reside in the same directory? Compile them both in one go.

    If you want to compile them one by one, ensure that Vehicle.class is on the classpath while compiling Car.java.