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.
#ThanksForReading
#HappyLearning

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

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

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
0
%d bloggers like this: