0
Error running this example
On my computer, I get the following msg while i try to do the exercise here, interface Animal { public void eat(); public void makeSound(); } class Cat implements Animal { public void makeSound() { System.out.println("Meow"); } public void eat() { System.out.println("omnomnom"); } } public class Program { public static void main(String[] args) { Cat c = new Cat(); c.eat();}} Error: Could not find or load main class undefined what did I do wrong?
4 ответов
+ 6
Post the code so that we can try to help.
+ 1
Yes but you need to put them into same package so that your Program class can load classes from others.
0
It means you didn't save your Java file same name as your class. Do you have Program.java Cat.java, 2 files? Are they using same package? I think you didn't name your main method class file, Program.java that is why JVM cannot detect your main method from Program.java
0
does that mean that i can keep multiple classes in one file as long as it's named after the one that has the main?