Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have more than one class containing the main() method in a Java project?

Tags:

java

main

eclipse

I have a doubt about Java.

In a Java project (handled by Eclipse for example), can I have more classes that contain the main() method and consequently can I chose to execute one class or another class?

Tnx

Andrea

like image 759
AndreaNobili Avatar asked Sep 25 '13 10:09

AndreaNobili


2 Answers

Yes, you can have more classes that contain the main() method, but at least one class which contain main() should be public so that JMV will start that class as Main thread

  • as the code written by aUserHimself represent
like image 62
Som Avatar answered Oct 26 '22 10:10

Som


You can have as many Classes as you want as long as each class have single main method.

You'll have to be opening a Specific Class in Eclipse if you wanna run main in that class or you can choose previously run classes from Eclipse Run Menuitem.

main means public static void main(String[] args) which is entry point in java programs.

like image 29
TheKojuEffect Avatar answered Oct 26 '22 10:10

TheKojuEffect