Posted on 2006-08-04 21:19
fxfeiyi 阅读(375)
评论(0) 编辑 收藏 所属分类:
SCJP
2. Given:
class CardBoard {
Short story = 5;
CardBoard go(CardBoard cb) {
cb = null;
return cb;
}
public static void main(String[] args) {
CardBoard c1 = new CardBoard();
CardBoard c2 = new CardBoard();
CardBoard c3 = c1.go(c2);
c1 = null;
// do Stuff
}
}
When // doStuff is reached, how many objects are eligible for GC?
A. 0
B. 1
C. 2
D. Compilation fails.
E. It is not possible to know.
F. An exception is thrown at runtime.
---------------------------------------------
> The object originally pointed to by c1 is eligible,
> because you have no reference to it. You still have
> a reference to the object pointed to by c2, because
> Java is pass by value, so in "go", the parameter is
> set to null, not c2. c3 never gets an object--it is
> set to null immediately, because null is the return
> value of c1.go(c2).