Translate

Thursday 9 January 2014

Is it possible to overload main() method of java. If yes, explain with example.

Ans:
Yes, it is possible to overload main() method in java. You can have more than one main method but with different argument list.
A simple example of overloading main method:

//Test.java
class Test
{
public static void main(String abc[])
{
System.out.println("In Main method");
main(10);
}
static void main(int num)
{
System.out.println("Overloaded main method : prints number :" + num);
}
}

No comments:

Post a Comment