Q)
What if the main method is
declared as private?
The program compiles properly but at
runtime it will give "Main method not public." Message
Q) What if the static modifier is removed
from the signature of the main method?
Program compiles. But at
runtime throws an error "NoSuchMethodError".
Q) Can you write “static public void” instead of “public static void” but not “public void static”.
Yes, We can write “static public void” instead of “public static void” but not “public void static”.
Q) If i do not provide the String array as
the argument to the method?
Program compiles but
throws a runtime error "NoSuchMethodError".
Q) If no arguments on the command line, String array of Main method will
be empty of null?
It is empty. But not null.
Q)
Can an application have multiple classes having main method?
A) Yes it is possible. While starting the
application we mention the class name to be run. The JVM will look for the Main
method only in the class whose name you have mentioned. Hence there is not
conflict amongst the multiple classes having main method.
Q) Can
I have multiple main methods in the same class?
A) No the program fails to compile. The compiler says that the main
method is already defined in the class.