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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "valid declarations of main()" Watch "valid declarations of main()" New topic
Author

valid declarations of main()

srinivas bolloju
Ranch Hand

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


please use the [code][/code] tags when showing code. visit <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page" target="_blank" rel="nofollow">http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page</a> ,for more details
manasa teja
Ranch Hand

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

HTH
thanks
Murthy


MT
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.


Amir
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: http://aspose.com/file-tools
 
subject: valid declarations of main()
 
Similar Threads
a question in Chapter One of RHE's book
Help me please
Two main methods in a java file
mainly about main( ).....
Javaprepare Question