Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

valid declarations of main()

 
srinivas bolloju
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
this is Q) from Khalid,
valid declarations of main()
a) static void main(String args[])
b) public static int main(String args[])
c) public static void main(String args)
d) final public static int main(String[] arguments)
e) public int main(String args[],int argc)
f) public void main(String args[])
accr to me valid answers are a) and d)
but answer given is only d)
why not a) pls see below.. this runs and prints hi.. Please explain...
 
manasa teja
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi bolloju..
please go thru this dicussion..

HTH
thanks
Murthy
 
Amir Ghahrai
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the purposes of SCJP exam you need to know the correct signature, which is an array of Strings, the correct return type which is void and the correct accessibility modifier which is public, and also static which belongs only to the class. declaring main as final doesn't change the above criteria.
although your code works fine, giving main a default modifier, or even private for that mattar, it's not suitable for the purposes of SCJP.
 
Deepali Pate
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also adding synchronized is also right.
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

why not a) pls see below.. this runs and prints hi.. Please explain...

This is really a bug. This won't run in JDK 1.4.0.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic