Does Java can have more than on main method?
Well, depending on the type of the question I can say that yes we can define more than one main method in a Java Program.But the difference will come when you will give the name to your Program, then the class having that name should have at-least one main method.
Example:
class Test1{
public static void main(String[] args)
{
System.out.println("This is Test 1");
}
}
class Test2{
public static void main(String[] args)
{
System.out.println("This is Test 2");
}
}
Explanation:
Now at the end of the Program, you have to just save it with the class name(Let's say Test1 in above code), which you want to be executed first.
Like: Test1.java
No comments:
Post a Comment