Compound Boolean Expressions

AP Computer Science A· difficulty 4/5

boolean a = true;
boolean b = false;
boolean c = true;
boolean r = a || b && c;
System.out.println(r);

What is printed?

  • A

    a

  • B

    compile error

  • C

    false

  • D

    true

    check_circle

Explanation

&& has higher precedence than ||, so this is a || (b && c) = true || (false && true) = true || false = true.

Want 10 more like this — adaptive to your weak spots?

Related questions