Java OCA OCP Practice Question 1163

Question

What is the output displayed by the following program?

public class Main {
   public static void main(String[] args) {
      String s1 = "ab";
      String s2 = "abcd";
      String s3 = "cd";
      String s4 = s1 + s3;/*  w ww.  ja v  a 2 s  . c o  m*/
      s1 = s4;
      System.out.print("s1 " + ((s1 == s2) ? "==" : "!=") + " s2");
   }

}
A.   s1 == s2   
B.   s1 != s2   
C.   s1   
D.   s1 == "abcd"   


B.

Note

Because s1 and s2 refer to different objects, s1 != s2 is true.




PreviousNext

Related