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
Published on 23-Apr-2018 10:49:25
Advertisements