0
Is this possible to implement code with two main function in Java?
If this is possible to compile a Java code with two main function then please understand me with an example.
1 Antwort
0
I don't believe so. Not in the same class. The main function provides a starting point for exacution and so too have two would cause ambiguity.
Further more the main function cannot be overloaded as the OS will always pass arguments in the form of a single String array.
The only way I can think of is to put the main function in a different class file. This would mean that java would call the main function of the file you exacuted. However, if you wish to distribute the code as a Jar this likely won't work in that format.