Make Selenium Easy

Java Interview Question 3 – Can We Overload main Method in Java?

As a part of Java Interview Questions, in this post, we will see a frequently asked interview question “Can we overload main method in Java?“.

When we keep more than one methods in a class with same method name but at least with one difference in its method signature (Number of arguments , Order of arguments and Type of arguments), is called as Method Overloading.

Note:- No return type is considered in overloading.

So can we overload main method in Java? Answer is Yes, We can.

Execution of a Java program starts from main() method. In fact we should say that Execution of a Java program starts from a main() method whose actual syntax is “public static void main(String[] args)”.

We can write multiple valid overloaded main method in a class but JVM always looks for a main method with syntax as “public static void main(String[] args)“. If it finds , it will start execution from there otherwise will give error stating “Error: Could not find or load main“.

Programming Example:-

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.

You can find all Selenium related post here.
You can find all API manual and automation related posts here.
You can find frequently asked Java Programs here.

Table of Contents

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

Java Interview Question 3 – Can We Overload main Method in Java?

by Amod Mahajan time to read: 1 min
%d bloggers like this: