Meaningless Drivel is fun!
The moose likes Java in General and the fly likes Overloading  the main method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Overloading  the main method " Watch "Overloading  the main method " New topic
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: 3989
    
  18

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.


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
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 :-)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overloading the main method
 
It's not a secret anymore!