Can We Overload main Method in Java?

Here you will get answer for very basic question asked by beginners i.e. can we overload main method in Java?

A function is overloaded in java by changing the number of arguments or their type. The main method can also be overloaded in the same way we overload any other method.

How Can We Overload main Method in Java?

Take below example.


String args[]

In above program there are 3 overloaded main methods. If you will run the program it will give above output. The JVM always looks for main method with following signature.

The main method acts as an entry point for program execution. Even though we have several main methods in program but JVM will still call main method having above signature.

You can call remaining overloaded main methods in the same way you call any overloaded method.

Comment below if you have doubts or found anything missing in above tutorial.

Leave a Comment

Your email address will not be published. Required fields are marked *