Multiple choice technology programming languages

Consider the following code snippet String s1="Hello"; String s2=s1; s1.concat("World"); System.out.println(s1+"---"+s2); What is the output??

  1. Hello---Hello

  2. Hello---HelloWorld

  3. HelloWorld---Hello

  4. HelloWorld---HelloWorld

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

String objects are immutable in Java. The concat() method returns a new String object but does not modify the original. Since s1.concat() is not assigned to any variable, s1 still points to Hello, and s2 also points to Hello.