+ 1

Can the main method be overloaded in java?

How can this be possible...? If at all the main method could be overloaded, it would mean that there are two(or more)methods with the name "main". Since the main method is implicitly provoked, which one of those overloaded main methods shall get executed?

19th Jan 2018, 5:43 PM
Kavya Sree Kante
Kavya Sree Kante - avatar
8 Answers
+ 2
Not sure. If yes, only one to run is one with correct parameters.
19th Jan 2018, 5:45 PM
Jacob Pembleton
Jacob Pembleton - avatar
+ 2
Yes, when main gets called, it will be called with the parameters that should be there, meaning that the others will never be used.
19th Jan 2018, 5:58 PM
Jacob Pembleton
Jacob Pembleton - avatar
+ 2
Yes
19th Jan 2018, 6:00 PM
Jacob Pembleton
Jacob Pembleton - avatar
+ 1
@Jacob Pembleton By "correct parameters"....do you mean.. a string array?
19th Jan 2018, 5:47 PM
Kavya Sree Kante
Kavya Sree Kante - avatar
+ 1
@Jacob Pembleton Then does that mean that overloading a main method is of no use? And only the one with the string array as its parameter type is valid?
19th Jan 2018, 6:00 PM
Kavya Sree Kante
Kavya Sree Kante - avatar
+ 1
@Jacob Pembleton Thanks for answering😊😊
19th Jan 2018, 6:03 PM
Kavya Sree Kante
Kavya Sree Kante - avatar
+ 1
@ Martin Taylor Thanks for answering 😊😊
19th Jan 2018, 6:16 PM
Kavya Sree Kante
Kavya Sree Kante - avatar