Can we overload the main method in Java?



Yes, we can overload the main method in Java, but When we execute the class JVM starts execution with public static void main(String[] args) method.

Example

Live Demo

public class Sample{
   public static void main(){
      System.out.println("This is the overloaded main method");
   }
   public static void main(String args[]){
      Sample obj = new Sample();
      obj.main();
   }
}

Output

This is the overloaded main method

Advertisements