Boolean Expressions

AP Computer Science A· difficulty 4/5

<code>if (b = true) ...</code> where b is boolean

  • A

    Throws exception

  • B

    Always enters if (assigns true to b, condition is true)

    check_circle
  • C

    Compares b to true

  • D

    Compile error

Explanation

Legal but bug-prone: assignment returns the assigned value (true).

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

Related questions