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)