public class Test { public static void main(String[] args) { String s1 = new String("Java"); String s2 = new String("Java"); System.out.print((s1 == s2) + " " + (s1.equals(s2))); } }

What is the output of the following code:


public class Test {
  public static void main(String[] args) {
    String s1 = new String("Java");
    String s2 = new String("Java");
    System.out.print((s1 == s2) + " " + (s1.equals(s2)));
  }
}


A. false false
B. true true
C. false true
D. true false

The correct answer is C
Your answer B is incorrect
Explanation: s1 == s2 is false, since s1 and s2 are two different objects. s1.equals(s2) is true since the equals method returns true if two strings have the same content.


Java

Learn More Multiple Choice Question :