Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

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

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic