Creating Objects: can anyone provide me the solution? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 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"); } }

16th Nov 2016, 8:40 AM
MAJID RAZZAK
MAJID RAZZAK - avatar
3 Answers
+ 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
16th Nov 2016, 11:05 AM
Dima Yakovenko
Dima Yakovenko - avatar
+ 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.
16th Nov 2016, 8:43 AM
Jakub Stasiak
Jakub Stasiak - avatar
0
thanks friends
17th Nov 2016, 11:56 AM
MAJID RAZZAK
MAJID RAZZAK - avatar