Can there exist two main methods in a Java program?

joey rohan picture joey rohan · Nov 15, 2012 · Viewed 101.3k times · Source

Can there exist two main methods in a Java program?

Only by the difference in their arguments like:

public static void main(String[] args)

and second can be

public static void main(StringSecond[] args)

If it is possible, which Method will be used as the entry point? How to identify this?

Answer

kosa picture kosa · Nov 15, 2012

As long as method parameters (number (or) type) are different, yes they can. It is called overloading.

Overloaded methods are differentiated by the number and the type of the arguments passed into the method

public static void main(String[] args)

only main method with single String[] (or) String... as param will be considered as entry point for the program.