Monday 18 March 2013

SCJP - 33 -Given Example


33. Which is true? (Choose all that apply.)

A. The invocation of an object’s finalize() method is always the last thing that happens
before an object is garbage collected (GCed).
B. When a stack variable goes out of scope it is eligible for GC.
C. Some reference variables live on the stack, and some live on the heap.
D. Only objects that have no reference variables referring to them can be eligible for GC.
E. It’s possible to request the GC via methods in either java.lang.Runtime or
java.lang.System classes.

Answer:

C and E are correct. When an object has a reference variable, the reference variable lives
inside the object, on the heap.

A is incorrect, because if, the first time an object’s finalize() method runs, the object
is saved from the GC, then the second time that object is about to be GCed, finalize()
will not run. B is incorrect—stack variables are not dealt with by the GC. D is incorrect
because objects can live in "islands of isolation" and be GC eligible. (Objective 7.4)

No comments:

Post a Comment