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. TrueBoth s1 and s2 refer to the same string literal from the string pool. Therefore s1 == s2 evaluates to true.

  1. A.

    True

  2. B.

    Compilation error

  3. C.

    Runtime error

  4. D.

    False

  5. 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.

Explore the full course: Rssb Basic Computer Instructor

Loading lesson…