1

when I am trying to run this code I am getting

Error: Could not find or load main class com.lara.CoffeeTest

can anybody tell me the reason

 class Coffee {
        int size;
    }

public class CoffeeTest {
    public static void main(String[] args) {
        Coffee drink= new Coffee();
        drink.size=2;
        System.out.println(drink.size);
    }
}
ankit
  • 4,919
  • 7
  • 38
  • 63

1 Answers1

0

java classpath doesn't contain your CoffeeTest.class file.java adds the current directory to the classpath by default unless there is CLASSPATH variable defined in the environment. You can make it work by executing the following

Change to the directory where 'com' directory resides and execute

//if CLASSPATH variable set in environment
java -cp . com.lara.CoffeeTest

or

java com.lara.CoffeeTest

provided you have compiled and .class files are present with the same package structure as that of source.

Keerthivasan
  • 12,760
  • 2
  • 32
  • 53