File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "GC Clarification" Watch "GC Clarification" New topic

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".

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:
subject: GC Clarification
It's not a secret anymore!