| Author |
Overloading the main method
|
Dazzy Rock
Greenhorn
Joined: May 19, 2012
Posts: 2
|
|
Is it possible in java to overload the main method ? or is it mandatory to use String[] args always
If possible then which version will be called by the JVM ?
and also what if a child class overrides the main () ?
Please, I am confused about this two topics which are commonly asked in interviews.
Explanation with example would help me to get a proper understanding.
Thankz in advance.
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3056
|
|
You can overload the main() method, it's just a simple static method like any other. However, the JVM will always call the public static void main(String[]) version.
You can not override it, because it's a static method. Static methods can never be overridden.
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
|
what happened when you tried this scenario? also i would like you to give a hint: static method cant override?
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
|
too slow ;)
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
|
welcome to javaranch Dazzy Rock !
|
 |
Dazzy Rock
Greenhorn
Joined: May 19, 2012
Posts: 2
|
|
|
thnks all for the reply.... being a new member of this community ... seems it's going to help me a lot :-)
|
 |
 |
|
|
subject: Overloading the main method
|
|
|