- Given:
- class CardBoard {
- Short story = 200;
- 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 //do stuff is reached, how many objects are eligible for GC [garbage collection]?
A. 0
B. 1
C. 2
D. Compilation fails
E. It is not possible to know
F. An exception is thrown at runtime
Answer:
C is correct. Only one CardBoard object (c1) is eligible, but it has an associated Short wrapper object that is also eligible.
Eu imaginava que seria letra B. Por que o objeto Short passa ser elegível se ele ainda tem tem a referencia dele? Desde já agradeço