Home » Java Programming » Java.lang Class

What will be the output of the program? String x = new String("xyz"); String y = "abc"; x = x + y; How many String objects have been created?

Correct Answer: 4

Explanation:

Line 1 creates two, one referred to by x and the lost String "xyz". Line 2 creates one (for a total of three). Line 3 creates one more (for a total of four), the concatenated String referred to by x with a value of "xyzabc".

← Previous Question Next Question→

More Questions from Java.lang Class

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion