Can we overload a main() method in Java?
Can we overload a main() method in Java?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can overload the
main()method, but onlypublic static void main(String[] args)will be used when your class is launched by the JVM. For example:That will always print
main(String[] args)when you runjava Test ...from the command line, even if you specify one or two command-line arguments.You can call the
main()method yourself from code, of course – at which point the normal overloading rules will be applied.EDIT: Note that you can use a varargs signature, as that’s equivalent from a JVM standpoint: