The method signature of a Java main() method is:
public static void main(String[] args){
...
}
Before the main method is called, no objects are instantiated. Having the static keyword means the method can be called without creating any objects first.
1. Since main method is static JVM can call it without creating any instance of class which contains main method.
2. If main method were not declared static than JVM has to create instance of main Class and since constructor can be overloaded and can have arguments there would not be any certain and consistent way for JVM to find main method in Java.
Let's simply pretend, that
static
would not be required as the application entry point.
A application class would then look like this:
class MyApplication {
public MyApplication(){
// Some init code here
}
public void main(String[] args){
// real application code here
}
}
Comments
Post a Comment