• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

main method

 
Tone Tucker
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have seen the main method in two forms and I know both work but which would be considered correct?

(a) public static void main(String args[] )

(b) public Static Void main (String[] args )


Thanks
Newbie
Tone...
 
fred rosenberger
lowercase baba
Bartender
Posts: 12186
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really, this has nothing to do specifically to the main method. Any array can be declared either way.

In general, the "String [] args" is preferred or more common, from my experience.
 
Manu Somasekhar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both are correct.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tone. Welcome to the Ranch!

Actually, not both are correct. Because you've got the capitalisation wrong of static and void in the second example - Java is case-sensitive, and so that won't compile. But I don't suppose that was what you were actually asking about .
 
Vijay Vishwa
Ranch Hand
Posts: 40
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the above 2 way mentioned is from screening test or any exam then the (b) is wrong as Matthew mentioned but (a) is correct

The preferred one is


Another way to declare from Java 5 onwards is

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic