Can we overload Java main method?

Java Programming Java8Object Oriented Programming

Yes, we can overload the main method of Java. But JVM will only call the default main method only. See the example below.

Example

Live Demo

public class Tester {
   public static void main(String args[]) {
     System.out.println("Default Main");  
   }
 
   public static void main(String args) {
      System.out.println("Overloaded Main");
   }
}

Output

Default Main
raja
Updated on 18-Jun-2020 07:47:37

Advertisements