java - number of objects for garbage collection -
given:
interface animal { void makenoise(); } class horse implements animal { long weight = 1200l; public void makenoise() { system.out.println("whinny"); } } public class icelandic extends horse { public void makenoise() { system.out.println("vinny"); } public static void main(string[] args) { icelandic i1 = new icelandic(); icelandic i2 = new icelandic(); icelandic i3 = new icelandic(); i3 = i1; i1 = i2; i2 = null; i3 = i1; //<-- line 14 } }
when line 14 reached, how many objects eligible garbage collector?
a. 0 b. 1 c. 2 d. 3 e. 4 f. 6
answer e. why?
after line14, original i2 object alive, no referemce point original i1 , i3, eligible garbage collector, , object has base of operations type, long field, lose to, 2*2 = 4;
java object inheritance garbage
No comments:
Post a Comment