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?

2nd Apr 2017, 2:22 PM
prodip
prodip - avatar
4 odpowiedzi
+ 6
Post the code so that we can try to help.
2nd Apr 2017, 3:03 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 1
Yes but you need to put them into same package so that your Program class can load classes from others.
2nd Apr 2017, 10:12 PM
Yhal Htet Aung
Yhal Htet Aung - avatar
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
2nd Apr 2017, 9:31 PM
Yhal Htet Aung
Yhal Htet Aung - avatar
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?
2nd Apr 2017, 9:47 PM
prodip
prodip - avatar