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
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>
Joined: Nov 11, 2002
Thanks Dan! I really appreciate the help. Keep up the good work with the mock exams!