Multiple choice technology programming languages

String s1=new String("abc"); String s2=new String("abc"); (s1==s2)-->result is

  1. true

  2. false

  3. compilation error

  4. exception thrown at runtime

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

When using 'new String()', a new String object is created on the heap each time, even if the character sequence is the same. s1 and s2 are two distinct objects with the same value 'abc'. The '==' operator compares object references, not content, so s1 == s2 returns false.

AI explanation

Using new String("abc") explicitly creates a new String object on the heap rather than reusing the interned string pool entry, so s1 and s2 reference two distinct objects even though their contents are identical. The == operator compares object references (identity), not content, so s1==s2 evaluates to false — you'd need .equals() to compare the actual character content.