I just posted a question and answer describing a tricking mock exam question that you'll run into on the OCAJP exam. You might even find it on the OCPJP exam as well.
The question itself walks through a discussion of the following code snippet:
A mock Java exam question would ask what the output would be, and provide a few sample answers, although I personally think an aspiring Java Professional should be able to figure out the answer without being given a few multiple choice answers to sort through.
I'm not sure whether the discussion was to be here or in the Q&A thread, but I don't want to look at the Q&A first and see the answer (even though I know it ;-)
The thing to remember is that, in any expression involving a post-fix operation, the value of the variable x before the "++" operation is used in evaluating the expression each time it appears. Further, the entire expression on the right will be evaluated before the "+=" operator is applied.
Since evaluation proceeds left-to-right:
x += x++ * x++ * x++;
by substitution, this is equivalent to:
x += (x) * (x+1) * (x+2)
x += (x^2 + x) * (x+2)
x += (x^3 + 2x^2 + x^2 + 2x)
x += (x^3 + 3x^2 + 2x)
x = x^3 + 3x^2 + 3x
so if x=2:
x = 2^3 + 3 (2^2) + 3(2)
x = 8 + 12 + 6
x = 26
If you think that's a toughie, try figuring out the cost of upgrading from the original "Java Platform 2" certification to the array of certifications available now that cover the same technical territory, and whether there is any "upgrade" discount!
The sad fact is one is likely to see such code in the wild, and have to maintain it, so IMHO such questions are valid. If nothing else they make you pay attention during the test. I'll bet those who complained also wanted a "participation" certificate if they didn't pass!
Besides, anything that makes you think can help stave off dementia.
It is entirely possible that one might have to maintain such a cryptic code base. However, one might have to do several other things as well while maintaining a code base. Does that mean they should all be on the test?
I feel that in the limited time and number of questions that a candidate has to be tested within, it believe it is better to focus on basic programming and language skills than on deciphering cryptic code.
A recruiter can always have a specialized evaluation if they have a special need for the candidate to be able to decipher cryptic code. After all, one test cannot fit all