• 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

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
 
What I don't understand is how they changed the earth's orbit to fit the metric calendar. Tiny ad:
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
reply
    Bookmark Topic Watch Topic
  • New Topic