Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Main method

 
Willie Toma
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this correct?
The main method can be something other than void, as long as there is a main method that is void.
Can a main method be anything thing as long as there is a void method?
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can. If you by that mean if you can overload main

Note! You can have the same parameter in the header. That is your overloaded main can take String args[]. Overloaded method must have diffrent parameterlist
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To start an application, the class you type after java,i.e.
java ClassName
must have a method with the signature
public static void main( String[] args )
or it won't start.
But you may have another method named main with different parameters (overloading main) if you wish. For instance
private static int main( String s )
or
double main( int i )
No problem.


[This message has been edited by Marilyn deQueiroz (edited September 22, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic