0
Is it possible to overload a main method?
Overloading Main Method
2 Réponses
+ 6
Yes, you can overload a main method, nothing stops from overloading,Overloading is also a feature of OOP languages in Java that is related to compile time (or static) polymorphism but JVM will always call the original main method, it will never call your overloaded main method.
+ 6
Zandro Gene Ortecio Yes, The main() method is a special method because it’s the entry point of Java application. The JVM will always call the main method to start the application. But as we said it’s a method so like any other method, we can overload it. You can overload the main method as per the method of overloading rules. You can overload it by the number of parameters or the type of parameters or both.
but how does it work?
When user do the action to start the application, The JVM always looks for the main method with its signature to launch the program. If the main() method is not defined with String parameters (String[] args) the JVM, not able to run it.