The following is an example of something I have feared would be on the
SCJP exam and marked incorrect, even though an incorrect answer actually
is the correct one.
SCJP Study Guide by Kathy & Bert, Chap 8 Self
Test (Inner Classes) problem 9.
The answer choices are:
A: An exception occurs at runtime
B: true
C: fred
D: Compilation fails because of an error on line 3
E: Compilation fails because of an error on line 4
F: Compilation fails because of an error on line 8
G: Compilation fails because of an error on a line other than 3,4 or 8
The answer given is G, but I believe the correct answer is F:
If you compile this code and run it, the compiler complains about line
8, expecting a ';'.
This is correct!! Just because line 7 closes out the anonymous class with
the '}', doesn't mean the ';' has to be on the same line, or even the
next line. All that needs to happen is that the ';' is the next token that
the compiler sees, even if there are a 100 blank lines after '}' and before
';'. I agree with good programming principles, that the ';' should be
after the '}' on line 7, but the compiler doesn't give a hoot about those
principles.
Thus, by choosing F instead of G, the answer would have been marked wrong
on the exam. And since you don't get to see what questions you missed,
you would not have thought that this answer was marked wrong.
Kathy & Bert, Please either prove me wrong here (Whew!) or what can
be done about this?
Thanks,
-Bruce