Question 136

What is the output of the Java code? String s1 = "abc";

What is the output of the Java code? String s1 = "abc"; String s2 = new String("abc"); System.out.println(s1 == s2); System.out.println(s1.equals(s2));
  1. Atrue then true
  2. Bfalse then true
  3. Ctrue then false
  4. Dfalse then false
Show answerHide answer

Correct answer: (B) false then true

Explanation

== compares references (different objects); equals() compares content.

From DSSSB TGT Computer Science Full Mock Test 1

This is question 136 of DSSSB TGT Computer Science Full Mock Test 1. See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.