Home > DeveloperSection > Interviews > Can we overload main() method?

Posted on    March-30-2015 2:17 AM

 Java Java 
Ratings:
 1 Answer(s)
  466  View(s)
Rate this:

Mayank Tripathi
Mayank Tripathi

Total Post:807

Points:4035
Posted on    March-30-2015 2:38 AM

Yes, by method overloading. We can have any number of main methods in a class by method overloading. Here is a example:

class Overloading1{  
  public static void main(int a){  
  System.out.println(a);  
  }  
    
  public static void main(String args[]){  
  System.out.println("main() method invoked");  
  main(10);  
  }  
}
Output : 10


Don't want to miss updates? Please click the below button!

Follow MindStick