关于java对象垃圾回收的有关问题

关于java对象垃圾回收的问题
01. interface Animal { void makeNoise(); }
02. class Horse implements Animal {
03. Long weight = 1200L;
04. public void makeNoise() { System.out.println("whinny"); }
05. }
06.
07. public class Icelandic extends Horse {
08. public void makeNoise() { System.out.println("vinny"); }
09. public static void main(String[] args) {
10. Icelandic i1 = new Icelandic();
11. Icelandic i2 = new Icelandic();
12. Icelandic i3 = new Icelandic();
13. i3 = i1; i1 = i2; i2 = null; i3 = i1;
14. }
15. }
直到第十四行,有多少对象可以被垃圾回收器回收
java 垃圾回收

------解决方案--------------------
4个对象。i1和i3都指向了11行创建的那个对象,i2为null。所以第十行和第十二行创建的那两个对象没有变量引用他们,所以可以回收。而且里面还有Long类型的对象可以被回收。一共四个。