Java OCA OCP Practice Question 1232

Question

What is the value displayed by the following program?

public class Main {
   public static void main(String[] args) {
      int x = 0;/* ww  w .  j  a  v a  2 s  . com*/
      boolean b1, b2, b3, b4;
      b1 = b2 = b3 = b4 = true;
      x = (b1 | b2 & b3 ^ b4) ? x++ : --x;
      System.out.println(x);
   }

}
  • A. -1
  • B. 0
  • C. 1
  • D. 2


B.

Note

From the ternary expression, the value of x must either be 0 or -1.

Because (b1 | b2 & b3 ^ b4) evaluates as (b1 | (b2 & (b3 ^ b4)), the answer is 0.




PreviousNext

Related