Is it possible to overload a main method? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is it possible to overload a main method?

Overloading Main Method

10th Sep 2020, 12:31 PM
Zandro Gene Ortecio
Zandro Gene Ortecio - avatar
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.
10th Sep 2020, 1:22 PM
Dreamer
Dreamer - avatar
+ 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.
12th Sep 2020, 3:51 AM
Raina Dhankhar
Raina Dhankhar - avatar