Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question on Dan's GC Question

 
Roan Nicolas
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Roan Nicolas
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dan! I really appreciate the help. Keep up the good work with the mock exams!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic