This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Can anybody explain me how there are 4 objects created? I know 3.
3. 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
Ans--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”. A, B, and D are incorrect based on the logic described above.
Perhaps its the creating of *two* strings on line 13? One is the literal "xyz" (created in a similar way to "abc" on the next line) and the other is created when the "new" operator is invoked. x refers to the "new" String; as stated the "xyz" literal is "lost".