- 1
Creating Objects: can anyone provide me the solution?
I am receiving the following error message on eclipse, when run the command: "Error: Main method not found in class Animal, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application." and the commands is class MyClass { public static void main(String[] args){ Animal dog = new Animal(); dog.bark(); } } public class Animal { void bark() { System.out.println("Woof-Woof"); } }
3 Respuestas
+ 2
No, you can have several classes in one file, but only ONE class can be public in this file. "main" method should be in public class. So, in your case, just make MyClass public and Animal class without any access modifier
+ 1
in file where is "main" method, there should be no other classes. Put your Animal class in other file and then include it. Rule for Java is: one file one class.
0
thanks friends