Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Can we overload the main() method

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 267
    Comment on it

    Overloading Main method:

    Like any other methods, it is possible to overload the main method also in java.

    One thing needs to be keep in mind while overloading the main method that it should be called inside some other main method.

    Lets see an example:

    class OverloadMain{  
      public static void main(int number){  
      System.out.println(number);
      main(10.5F)  
      }  
      public static void main(float number){  
      System.out.println(number);  
      }  
    
      public static void main(String args[]){  
      System.out.println("Inside main()");  
      main(6);  
      }  
    }  

    Note: It searches for the main() containing the parameters String args[] and the main() method which contains these parameters is the first to get executed and similarly other main() methods can be executed by calling them inside this one.

     

    So, output of the above code will be:

    Inside main()

    6

    10.5

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: