It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes valid declarations of main() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "valid declarations of main()" Watch "valid declarations of main()" New topic

valid declarations of main()

srinivas bolloju
Ranch Hand

Joined: Jan 23, 2001
Posts: 112
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...

please use the [code][/code] tags when showing code. visit <a href="" target="_blank" rel="nofollow"></a> ,for more details
manasa teja
Ranch Hand

Joined: May 27, 2002
Posts: 325
hi bolloju..
please go thru this dicussion..


Amir Ghahrai
Ranch Hand

Joined: Jun 19, 2002
Posts: 110
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

Joined: Mar 20, 2002
Posts: 114
Also adding synchronized is also right.
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055

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.
I agree. Here's the link:
subject: valid declarations of main()
It's not a secret anymore!