Java OCA OCP Practice Question 524

Question

Which of the following expressions are legal? (Choose all that apply.)

  • A. int x = 16; x = !x;
  • B. int x = 16; if (!(x > 3)) {}
  • C. int x = 16; x = ~x;


B, C.

Note

In option A, the use of ! is illegal because x is of int type, not boolean.

In option B, the comparison operation is valid, because the expression (x > 3) is a boolean type and the ! operator can properly be applied to it.

In option C, the bitwise inversion operator is legally applied to an integral type.




PreviousNext

Related