Compound Boolean Expressions

AP Computer Science A· difficulty 3/5

int age = 17;
boolean hasLicense = true;
if (age >= 16 && hasLicense) {
  System.out.println("can drive");
} else {
  System.out.println("cannot drive");
}

What is printed?

  • A

    true

  • B

    false

  • C

    cannot drive

  • D

    can drive

    check_circle

Explanation

Both conditions are true: age >= 16 (17 >= 16) and hasLicense (true). The && evaluates to true, printing "can drive".

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

Related questions