Hi Ranchers,
Here is my question - Source:
SCJP 5 Guide by K&B: Q5. Page 391 / 402
Given:
Which, inserted at line 4, produces the output 12?
A. int y = x;
B. int y = 10;
C. int y = 11;
D. int y = 12;
E. int y = 13;
F. None of the above will allow compilation to succeed.
Answer: >
C is correct. x reaches the value of 11, at which point the while
test fails. x is then incremented (after the comparison test!), and the println() method runs.
> A, B, D, E, and F are incorrect based on the above.
My Question: Since postfix operators (as well as prefix unary operators) have higher precedence than relational operators; why isn't x++ evaluated before < operator in the do{} while() expression in the question above? Going by that the correct answer should be option D.
---------
Ravinder