Is it possible to overload a main method? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
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 ответов
+ 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