This week's book giveaway is in the Agile and Other Processes forum. We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line! See this thread for details.
For the below code, how many objects are eligible for collection after line 6 ?
Answer says 2. But I can only see 1 object is eligible. After line 3, c1 points to object1. After line 4, object1 becomes eligible; both c1,c2 point to new object2. After line 5, c3 points to object3. After line 6, c2, c3 point to object3; c1 still points to object2.
after line 6, how many objects are eligible for garbage collection?
None of the above
Explanation: No Explanation Available
Also another one from the same page: these may just be badly formated, but the below code seems to create only 2 objects.
1. StringBuffer s1 = new StringBuffer("abc"); 2. StringBuffer s2 = s1; 3. StringBuffer s3 = new StringBuffer("abc"); How many objects are created ?
The first question has already been discussed numerous times (search these forums for 'anotherMethod').
The answer to the second question depends on the exact wording of the question - when that particular code is executed only two objects are created (the 2 StringBuffers). However, at the time the class was loaded, a String containing the value "abc" would also have been created.
We don't have time to be charming! Quick, read this tiny ad:
a bit of art, as a gift, that will fit in a stocking