This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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