aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Self_Exam Chapter 3 SCJP Number 11 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Self_Exam Chapter 3 SCJP Number 11 " Watch "Self_Exam Chapter 3 SCJP Number 11 " New topic
Author

Self_Exam Chapter 3 SCJP Number 11

Ted North
Ranch Hand

Joined: Jan 02, 2012
Posts: 193
    
    1

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
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40



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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Praveen Kumar M K
Ranch Hand

Joined: Jul 03, 2011
Posts: 256
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

Joined: Jul 03, 2011
Posts: 256
You could try with this, it will give more clarity.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Self_Exam Chapter 3 SCJP Number 11