when there is a file having two classes and each class has a main method respectively , then which main method would get invoked when we try to run it ?
The one from the class you specify with the "java" command. The JVM doesn't check all classes on the class path to see if they have a main method - it simply listens to you and if you've given the name of a class without a main method it will simply throw an error.
jose chiramal wrote:when there is a file having two classes and each class has a main method respectively , then which main method would get invoked when we try to run it ?
Did you try it out yourself? What did you observe.
Hint: Think about how you run it.