Hi All,
I was wondering if there is anyone in here who could help me to understand a question in K&Bs guide to the SCJP exam. We've been discussing it in
this thread in the SCJP forum. I'm trying to understand exactly what consititues an object in Java. Specifically, does placing a literal in the String Buffer pool constitute creating an object? If so, by what definition of an object.
Here is the question from the book. What definition of object is the basis for saying that line 13 creates two objects?
-------------------------------------------------------------------
Question
Given the following,
13. String x = new String("xyz");
14. y = "abc";
15. x = x + y;
how many String objects have been created?
A. 2
B. 3
C. 4
D. 5
-------------------------------------------------------------------
Answer
C. Line 13 creates two, one referred to by x and the lost String �xyz�. Line 14 creates one (for a total of three). Line 15 creates one more (for a total of four), the concatenated String referred to by x with a value of �xyzabc�.
--------------------------------------------------------------------
Thanks,
Keith
[ May 25, 2004: Message edited by: Keith Leng ]