Hey Guys, I am creating this blog to share deep knowledge in Java, JSP, Servlets, JDBC, Hibernate, Spring and Spring MVC in details.

Can We Overload main() method in Java?


Can We Overload main() method in Java?

Yes, by method overloading. You can have any number of main methods in a class by method overloading. But JVM calls a main() method which receives string array as arguments only. Let's see the simple example:

public class OverloadExample {
     public static void main(String[] args) {
           System.out.println("main with String[]");
     }
     public static void main(String args) {
           System.out.println("main with String");
     }
     public static void main() {
           System.out.println("main without args");
     }
}

Output: main with String[]


Share:

Related Posts:

No comments:

Post a Comment

Popular Posts