aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A question on Dan's GC Question 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 "A question on Dan Watch "A question on Dan New topic
Author

A question on Dan's GC Question

Roan Nicolas
Greenhorn

Joined: Nov 11, 2002
Posts: 23
Hi Fellow Ranchers! First of all, I would to thank everyone who have contributed to this forum. I'm on the process of studying for my SCJP and I'm really learn a lot from the different topics posted here. Anyway, I have a question with regards to one of Dan's Mock Exam Question on Garbage Collection.
Question 1:

After method m1 returns the objects on which of the following lines are eligible for garbage collection?
a. 1
b. 2
c. 3
d. 4
e. None of the above.
f. Compiler error.
g. Run time error.
h. None of the above.
Question 2:

After method m1 returns the objects on which of the following lines are eligible for garbage collection?
a. 1
b. 2
c. 3
d. 4
e. None of the above.
f. Compiler error.
g. Run time error.
h. None of the above.
I believe the answer to Question 1 is letter E and the answer to Question 2 is letter B, C, D.
My question is how come when the reference of the array is set to null (Question 1), it is not eligible for garbage collection but if its elements were set to null (Question 2) then they would be eligible? Is this really how the garbage collection works?
Thanks


Owee<p>SCJP 1.4
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Thank you for using my exam.
The first question is really a trick question that would also be a good question for the exam objective that covers parameter passing. The array reference that is set to null is local to method m1 and does not have any effect on the array reference in the main method. If you run the program you will see that the output is ABC.
This is a very important concept to learn because the real exam has a lot of trick questions similar to this one.


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Roan Nicolas
Greenhorn

Joined: Nov 11, 2002
Posts: 23
Thanks Dan! I really appreciate the help. Keep up the good work with the mock exams!
 
 
subject: A question on Dan's GC Question