deyvid
Maio 4, 2010, 12:12pm
#1
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
deyvid:
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
Tipo nessa mesma pagina tem um topico com respostas para a mesma pergunta. Mas quando c1 recebe null o objeto story fica na especie de “ilha de isolamento” onde nao tem como mais ser acessado por isso sao dois objetos.