• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Self_Exam Chapter 3 SCJP Number 11

 
Ted North
Ranch Hand
Posts: 201
1
Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my impression of which objects are created and how the references relate to them:





When line 16 is reached, how many objects will be eligible for garbage collection?
A. 0
B. 1
C. 2
D. 3
E. 4
F. 5

I selected D

The answer says that "B is correct. It should be clear that there is still a reference to the object referred to by a2, and that there is still a reference to the object referred to by a2.b2. What might be less clear is that you can still access the other Beta object through the static variable a2.b1 - because it's static" (K & B, 2000-something, p. 285).

What am I missing here? 0_o

*** Also which b1 and b2 are set to null? The class variable of Alpha and its instance variables or the variables declared in main and their instances?
 
Henry Wong
author
Marshal
Pie
Posts: 21420
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Can you explain the diagram? Some parts of it doesn't make sense, like how does an object variable point to a local variable?

Henry
 
Praveen Kumar M K
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ted,

I agree with the answer if the GC check was at line 14(I would suggest you take a crack at it again!), but line 16 looks like out of scope of main() method...so shouldn't all the 4 objects be available for GC at line 16?

Regards,
Praveen.
 
Praveen Kumar M K
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try with this, it will give more clarity.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic