QuestionQ32

Working with Selected Classes from the Java API

Given the following code:

Question Image

What is the result?

  • A false, false
  • B false, true
  • C true, false
  • D true, true
Explanation

String.equals() compares the character contents of strings, so str1.equals(str3) is true because both contain Java. The == operator compares object references; str3 is created through runtime concatenation and is not the same object as the str1 literal, so that comparison is false.

Community Discussion

No comments yet. Be the first to start the discussion!