CAN WE OVERLOAD MAIN() METHOD?

Samuel Fernandes

Total Post:38

Points:190
Posted by  Samuel Fernandes
Java 
 648  View(s)
Ratings:
Rate this:
  1. Mayank Tripathi

    Post:807

    Points:4035
    Can we overload main() method?

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!