What will be the result of the following Java code? public class MyString {…
2024
What will be the result of the following Java code? public class MyString { public static void main(String[] args) { String s1 = "Program"; String s2 = "Program"; System.out.println(s1 == s2); } }
Answer: A. True — Both s1 and s2 refer to the same string literal from the string pool. Therefore s1 == s2 evaluates to true.
- A.
True
- B.
Compilation error
- C.
Runtime error
- D.
False
- E.
Question not attempted
Attempted by 297 students.
Show answer & explanation
Correct answer: A
Both s1 and s2 refer to the same string literal from the string pool. Therefore s1 == s2 evaluates to true.
Loading lesson…