Can there exist two main methods in a Java program?
Only by the difference in their arguments like:
public static void main(String[] args)
The below code in file "Locomotive.java" will compile and run successfully, with the execution results showing
2
As mentioned in above post, the overload rules still work for the main method. However, the entry point is the famous psvm (public static void main(String[] args))
public class Locomotive {
Locomotive() { main("hi");}
public static void main(String[] args) {
System.out.print("2 ");
}
public static void main(String args) {
System.out.print("3 " + args);
}
}