Here is a small piece of code I got from another mock exam site:
public class doublemain
{
int x;
public static void main(Integer args[])
{
System.out.println("in main method with int args");
}
public static void main(
String args[])
{
System.out.println("In main method with string args");
}
}
It was asked whether the code will compile and if yes then which version of main() will run.
The answer to this is: Yes the code compiles and the method of main that will run is the main() function taking the string args irrespective of the order in which they are written.
I am a newbie to
Java can someone explain then why does Java allow for overloading of the main method if it knows that it will always run the String version (or so I suppose ?)
Please guide me in this matter
Thnx in advance