下面的程序代码新建出数个对象。你的任务是要找出“最受欢迎”的对象,也就是被最多变量所引用的对象。还有,标记出所有对象以及对它的引用。我们已经先帮你标记出一个对象。
class Bees {
Honey [] beeHA;
}
class Raccoon {
Kit k;
Honey rh;
}
class Kit {
Honey kh;
}
class Bear {
Honey hunny;
}
public class Honey {
public static void main(String [] args) {
Honey honeyPot = new Honey();
Honey [] ha = {honeyPot,honeyPot,honeyPot,honeyPot};
Bees b1 = new Bees();
b1.beeHA = ha;
Bear [] ba = new Bear[5];
for (int x = 0;x < 5;x++) {
ba[x] = new Bear();
ba[x].hunny = honeyPot;
}
Kit k = new Kit ();
k.kh = honeyPot
Raccoon r = new Raccoon();新的Raccoon对象
引用它的变量
r.rh = honeyPot;
r.k = k;
K=null;
} // main函数结束
} 