Boolean Expressions

AP Computer Science A· difficulty 2/5

String a = "cat";
String b = "dog";
if (a.equals(b)) {
  System.out.println("same");
} else {
  System.out.println("different");
}

What is printed?

  • A

    same

  • B

    different

    check_circle
  • C

    compile error

  • D

    true

Explanation

"cat".equals("dog") is false because the strings have different content, so the else branch prints "different".

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

Related questions