> but when we run the program , we are not calling the
> main() method.
> then how this happens.?
The name of the starting class is given as a parameter to the Java runtime system when a program is started. The runtime system then will look for the main method in the specified class. You can have many main methods in a Java program. The one that gets called is the one you specify to the runtime system when the program is started. This is also where you specify the parameters to the String array in the main method.
You can have many main methods in a Java program. The one that gets called is the one you specify to the runtime system when the program is started. This is also where you specify the parameters to the String array in the main method.
========
say, we have more than one main() method in the java program.
how we have to mention the particular main() method to the java runtime system ?
can you explain a litte bit further?
=========
It means main method can be overloaded. But the JVM will look for
public static void main(String[] args) or
public static void main(String... args)
if the same class contains the another main method such as
public static void main(int i) {
}
JVM will not invoke this method. You have to manually invoke in your program.
> how we have to mention the particular main() method
> to the java runtime system ?
By naming the class whose main you wish to call when you start the JVM. Example:
java HelloWorld
...will call the HelloWorld class' main() method, provided it has the appropriate signature as mentioned above.
~