Multiple choice technology programming languages

import java.lang.*; class A { public static void main(String[] args) { String s1=new String("TCS"); String s2=s1; System.out.println(s1==s2); System.out.println(s1.equals(s2)); } } What is the Result?

  1. true true

  2. true false

  3. false true

  4. Exception

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

When s2 = s1 assigns the reference, both variables point to the same String object in memory. The == operator returns true because they're the same reference. The equals() method also returns true because String's implementation compares content, which is identical.

AI explanation

Here s2 = s1 simply copies the reference, so both variables point to the exact same String object in memory — meaning s1 == s2 (reference comparison) is true. And since they're literally the same object, s1.equals(s2) (content comparison) is also trivially true. This differs from the classic string-pool gotcha where new String(...) vs. a literal produces different references; here there's only one object being compared to itself.