Can we overload the main method in Java?

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 08-Jan-2018 13:11:18
Advertisements