-2

"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?

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
kretosian
  • 9
  • 3

1 Answers1

1

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.

Queeg
  • 7,748
  • 1
  • 16
  • 42
  • how can i compile car.java after Vehicle.java one by one using classpath – kretosian Oct 05 '22 at 11:23
  • `PS D:\Programming\java2> javac vehicles\Car.java ` `Usage: javac use --help for a list of possible options` **this is also not working** – kretosian Oct 05 '22 at 11:51