I have following class.
public class Test {
public static void main(Integer[] args) {
System.out.println(\"This is not a main\");
}
Command-line arguments are arguments to the main()
method which are passed to it at run-time. Since Java uses only String
type command-line arguments, the JVM ignores the other main()
method which passes Integer.
This is the only signature recognized by the JVM as THE MAIN METHOD
public static void main(String[] args)
You can have as many overloaded main method as you want BUT only the method with the above signature will be called by the jvm
As others have said, the main
method will always be called by the JVM with the overload that takes a string array. You are free to make other overloads to that metod if you so wish. You may even call them yourself in your code. It's just that the VM specifically looks for that one overload that takes an array of strings.
Since command line arguments are always Strings
.