This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes GC Clarification Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "GC Clarification" Watch "GC Clarification" New topic
Author

GC Clarification

Vidyavathi saravanan
Ranch Hand

Joined: Sep 24, 2004
Posts: 34

Answer options:
Assume that garbage collection runs and all elligible objects are collected and finalized.
A It does not compile due to incorrect signature of the finalize method.
B It compiles but no text is written when it runs due to incorrect signature of the finalize method.
C Before "exiting" is written, 2 messages from finalize will be printed.
D Before "exiting" is written, 3 messages from finalize will be printed

Which one would be the answer?
(code tag fixed and missing }s added )
[ November 09, 2004: Message edited by: Barry Gaunt ]
Jay Pawar
Ranch Hand

Joined: Aug 27, 2004
Posts: 411
I think the answer should be option C. There are two objects which are eligible for garbage collection.
They are the ones which are generated when i=0; and i=1; the object created when i=2; has reference t and obj.

Hope that helps you.
[ November 08, 2004: Message edited by: Jay Pawar ]

Cheers,<br />Jay<br /> <br />(SCJP 1.4)<br />Heights of great men were not achieved in one day, they were toiling day and night while their companions slept.
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Hi Vidyavathi,

I think none of the answers are correct. Even with the assumption that the garbage collector is run, the 2 messages could be printed before or after the "exiting".

Joyce
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Joyce is correct. I have just compiled and run the program to get:



Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
PNS Subramanian
Ranch Hand

Joined: Jul 13, 2004
Posts: 150
Assume we face a question like the one above, aren't we suppose to go with option (c) since thats the only possibility ?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
No, you write to the author of the mock exam and tell them they're wrong.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GC Clarification
 
Similar Threads
Brogden's mock exam Question
Need help on this piece of code about GC and finalize()
Garbage Collection & finalize() calls
Break back to Topic Menu
Threads and Synchronization examples