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???
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. cheers
Co-Author of <a href="http://www.amazon.com/exec/obidos/ASIN/0596007124/ref=jranch-20" target="_blank" rel="nofollow">"Head First Design Patterns"</a><br /> <br />Just a Jini girl living in a J2EE world.