It is specified that the correct signature of main method is -
public static void main(
String args[]){/*...*/}
Static because the
java interpreter calls this method in a static context, and public because it should be accessible to the interpreter.
But if this thing is in the Java language specification... how come I'm able to compile (and run - perfectly) an application using this -
<code>
private static void main(String args[]){/*...*/}
</code>
this -
<code>
protected static void main(String args[]){/*...*/}
</code>
and this -
<code>
static void main(String args[]){/*...*/}
</code>
??
And after you've solved this problem of mine... will you please explain why would this -
//MeraMain.java
public class MeraMain{
private static void main(String args[]){
System.out.println("MeraMain's main!!");
}
}
class MeraSubMain extends MeraMain{}
when invoked with the following command -
java MeraSubMain
would give the following output -
MeraMain's main!!
??
As the MaraMain Main is, after all, private.