• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Sun's Sample Question..

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the answer to the following question? Please explain.
1 public class X {
2 public void m(Object x) {
3 x = new Integer(99);
4 Integer y = (Integer)x;
5 y = null;
6 System.out.println("x is" + x);
7 }
8 }
When is the Integer object, created in line 3, eligible for garbage collection?
A) never
B) just after line 4
C) just after line 5
D) just after line 6 (that is, as the method returns)
E) when the calling method sets the argument it passed into this method to null
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1 public class X {
2 public void m(Object x) {
3 x = new Integer(99); // x is created
4 Integer y = (Integer)x; // y points to same object as x
5 y = null; // y is set to null, x still points to same object
6 System.out.println("x is" + x);
7 } //x leaves scope
8 }
When is the Integer object, created in line 3, eligible for garbage collection?
A) never
B) just after line 4
C) just after line 5
D) just after line 6 (that is, as the method returns)
E) when the calling method sets the argument it passed into this method to null
I think the answer is D, see comments above.
Can someone confirm this?
 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob
yes 100% correct.
Regards
Prasad
 
It's a tiny ad only because the water is so cold.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic