Q. What is the output of the following code snippet?
Code:String s1 = “Hello”; String s2 = new String(“Hello”); System.out.println(s1 == s2);
β
Correct Answer: (B)
False
Explanation: In this case, s1 is a string literal and s2 is a string object created using the new keyworD) When a string object is created using the new keyword, a new object is created in memory even if the value is the same as an existing string. Therefore, s1 and s2 do not refer to the same object in memory, so s1 == s2 returns false.