1 Replies - 847 Views - Last Post: 30 November 2010 - 12:33 AM Rate Topic: -----

#1 BuhRock   User is offline

  • D.I.C Regular

Reputation: 10
  • View blog
  • Posts: 256
  • Joined: 21-February 10

Main Method Question

Posted 29 November 2010 - 10:56 PM

Hi, I have a question about the main method. I have noticed that in some peoples code, they put
public static void main(String[] args)
as the main method header. Then in others I see
public static void main(String args[])

Why is it that this works both ways? Also what is the difference?
Is This A Good Question/Topic? 0
  • +

Replies To: Main Method Question

#2 masijade   User is offline

  • D.I.C Addict
  • member icon

Reputation: 196
  • View blog
  • Posts: 580
  • Joined: 03-April 10

Re: Main Method Question

Posted 30 November 2010 - 12:33 AM

No real difference just a varying syntax. In general the second form is frowned upon in most formatting conventions but that is more organisational than anything else.

There is, however, one thing the second form (i.e. putting the brackets on the variable rather than the type) will allow you to do that the first won't however (and this is general declaration stuff nothing to do with main itself) and that is something like this
int a, b, c[];

where a and b are normal ints and c is an int array.
That, however, is also frowned upon in most formatting conventions. Again, though, this is more organisational than anything else.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1