• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question from Sybex practice exam

 
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 499
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.Thank you.
 
So you made a portal in time and started grabbing people. This tiny ad thinks that's rude:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic