File Name = multiple_main_methods.java
class multiple_main_methods_two {
public static void main(String[] args){
System.out.println("Class second");
}
}
class multiple_main_methods_one {
public static void main(String[] args){
System.out.println("Class first");
}
}
Output
Class first
IDE used - IntelliJ IDEA
CodePudding user response:
IntelliJ is choosing a class to execute. Remember, you execute the main method in a class, not in a file.
Check it in your Run configurations enter image description here
CodePudding user response:
It is not giving error because your main methods belong to different classes i.e. multiple_main_methods_two and multiple_main_methods_one which is completely fine.