Java OCA OCP Practice Question 950

Question

In the following code fragment, line 4 is executed.

1. String s1 = "xyz"; 
2. String s2 = new String(s1); 
3. if (s1 == s2) 
4.      System.out.println("Line 4"); 
  • A. True
  • B. False


B.

Note

Line 1 constructs a new instance of String and stores it in the string pool.

Line 2 explicitly constructs another instance.




PreviousNext

Related