I came across this question, in a mock exam...
Which of the following expressions results in a positive value in x?
A. int x = -1; x = x >>> 5;
B. int x = -1; x = x >>> 32;
C. byte x = -1; x = x >>> 5;
D. int x = -1; x = x >> 5;
The answer is A, but C got me wondering. It is not legal syntax and does not compile, as is. You have to cast x in order to get the line to work.
byte x = -1; x = (byte)(x >>> 5);
It still results in a negative and would not be a correct choice, however, what if it would have been a correct choice? Do the questions get that tricky? The question was not about legal syntax, yet there was some illegal code in the answers.
My thought was that it is an error on the
test author's part, but it made me wonder.