• 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

Help!!, problem with Dan question

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Help, I confuse with this question of Dan Chrisholm. Thanks Dan to think up a lot of creative questions .

Which of the following are true statements and which of the following could be a result of attempting to compile and run the program?
a. Prints: XY
b. Prints: YX
c. Prints: XXYY
d. Prints: YYXX
e. Nothing is printed.
f. There is no guarantee that the garbage collector will run.
g. Compiler Error.
h. Run Time Error.
i. None of the above.
The answer is a,b,e,f .
plzzz anybody help me, Why the answer can be also be b,e,f, because I think it only a. What is actually happens in this code??
Thanks a lot.
Edited by Corey McGlone: Added Code Tags
[ March 22, 2003: Message edited by: Corey McGlone ]
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One key thing to remember when dealing with garbage collection is that there are no guarantees about when of even if it will execute.
Therefore, we have no idea if the garbage collector will execute at all, making answers e and f correct.
Also, we have no guarantee as to what order the garbage collector will collect unused objects, therefore, answers a and b are also correct.
Hope that helps,
Corey
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Corey,
Please correct me if I am wrong. I do not understand how a and b could be the correct answers. I sure do understand that that e and f are correct answers.
As far as my understanding goes, I think any object that has references to it cannot be Garbage collected.
Hence assuming that the did succeed to invoke the Garbage collection thread, how could these objects (i.e. x1 and y1) be garbage collected ?
-Harry.
[ March 23, 2003: Message edited by: Harry D'Souza ]
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When method m returns both objects, x1 and y1, are out of scope and are eligible for garbage collection.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic