Java OCA OCP Practice Question 956

Question

In the following code fragment, line 4 is executed.

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


A.

Note

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

In line 2, "xyz" is already represented in the pool, so no new instance is constructed.




PreviousNext

Related