Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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: 3594
    
  14

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 :-)
 
wood burning stoves
 
subject: Overloading the main method
 
Similar Threads
Method Overloading
Polymorphism
Operator Overloading
Polymorphism
access modifiers for main method