File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Sun Sample exam: mistake?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Sun Sample exam: mistake??" Watch "Sun Sample exam: mistake??" New topic

Sun Sample exam: mistake??

Alfred Kemety
Ranch Hand

Joined: Aug 14, 2002
Posts: 279
The question is:
What is the result?
A- x = 0
B- x = 1
C- x = 2
D- x = 3
E- x = 4
F- Compilation fails
The code is as follows: (note the private modifier of the main method)

The answer is:
Option E is the correct answer. The instance variable b is initialized to false, reset to false on line 8 and falls through to line 15, where x is set to 4.
If the main method was declared public then this answer should have been fine.. but since it's private, it will compile but will print "Main method not public."
Am I missing something???

Alfred Raouf - Egypt - SCJP 1.4<br />Kemety.equals(Egyptian) // returns true
Kathy Sierra
Cowgirl and Author

Joined: Oct 10, 2002
Posts: 1589
We made a mistake on that question! It was never legal to mark the main method private, but it used to actually compile and run under some flavors of 1.3 (fixed in 1.4). Anyway, that sample question is being fixed to make the main method public.

Co-Author of Head First Design Patterns
Just a Jini girl living in a J2EE world.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Hi Kathy,
would you like to elaborate on that "we"?
Do you mean you're from "S...huuuush"?
[ October 11, 2002: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
I agree. Here's the link:
subject: Sun Sample exam: mistake??
jQuery in Action, 3rd edition