Java Programming - Java.lang Class - Discussion

Discussion Forum : Java.lang Class - Finding the output (Q.No. 1)
1.
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?
2
3
4
5
Answer: Option
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".

Discussion:
31 comments Page 4 of 4.

Sanjay Singh said:   1 decade ago
I am not able t ounderstand the concept behind the answer.Kindly exlpain the solution in detail.


"Line 1 creates two, one referred to by x and the lost String "xyz"----------Please ellaborate.


Post your comments here:

Your comments will be displayed after verification.