• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overloading the main method

 
Dazzy Rock
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 5371
52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what happened when you tried this scenario? also i would like you to give a hint: static method cant override?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
too slow ;)
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
welcome to javaranch Dazzy Rock !
 
Dazzy Rock
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thnks all for the reply.... being a new member of this community ... seems it's going to help me a lot :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic