• Post Reply Bookmark Topic Watch Topic
  • New Topic

Q from http://examsguide.com/ - GC eligible  RSS feed

 
Clay Chow
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From http://examsguide.com/scjp/freequestions2.html:

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?


Ans: 1

Ans: 2

Ans: 3

Ans: 4

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.


14)

1. StringBuffer s1 = new StringBuffer("abc");
2. StringBuffer s2 = s1;
3. StringBuffer s3 = new StringBuffer("abc");
How many objects are created ?


0

Ans: 1

Ans: 2

Ans: 3

Explanation:
No Explanation Available

Ans: 4
[ November 26, 2008: Message edited by: Clay Chow ]
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!