Multiple choice technology programming languages

What is displayed when the following code is compiled and executed? String s1 = new String("Test"); String s2 = new String("Test"); if (s1==s2) System.out.println("Same"); if (s1.equals(s2)) System.out.println("Equals");

  1. Same Equals

  2. Equals

  3. Same

  4. The code compiles, but nothing is displayed upon execution.

  5. The code fails to compile.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The == operator compares object references, not content. s1 and s2 are different objects (created with new String()), so s1 == s2 is false. The equals() method compares String content, so s1.equals(s2) is true. Only "Equals" is printed. Option A would require both references to point to the same object.