New course! Every coder should learn Generative AI!
Try a free lesson0
Is it possible to overload a main method?
Overloading Main Method
2 Answers
+ 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.