• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Question from Sybex practice exam

 
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Answer is Immediately after line 10.

But shouldn't the answer be after line 4? Because temp is local variable and local variables go out of scope after method exits ,becoming eligible for garbage collection.

Thanks,
Veena
 
Ranch Hand
Posts: 271
5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Veena Pointi wrote:
Answer is Immediately after line 10.

But shouldn't the answer be after line 4?


The answer seems correct to me.

Veena Pointi wrote:
Because temp is local variable and local variables go out of scope after method exits
Veena


Indeed

Veena Pointi wrote:
becoming eligible for garbage collection.

Thanks,
Veena

This happens immediately after line 10 for the String object instantiated on line 3 because there will no longer be any references to it then.  Specifically, at the aforementioned method exit, the String reference is returned, assigned to the result String reference, printed, and after line 10 since the code no longer references  the String object instantiated on line 3, then the String object instantiated on line 3 becomes eligible for garbage collection.

Does that help?
 
Veena Pointi
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.Thank you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!