【发布时间】:2014-03-21 10:30:01
【问题描述】:
在继承中,为子类创建对象时,是否也为其超类创建对象?
我发现上述问题的答案是肯定的,它是创建的。我对吗?基于正确的假设,我解决了这个问题,我发现答案是 4。 我说的对吗?
long 是原始类型还是包装类?
问题:到达最后一个大括号时,有多少对象符合垃圾回收条件?
interface Animal {
void makeNoise();
}
class Horse implements Animal {
Long weight = 1200L;//here is Long a primitive variable or a wrapper class??
//If it is a wrapper class object, I think the answer to the
// question would be 6
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;
}
}
【问题讨论】:
-
第一个问题,看this
标签: java inheritance garbage-collection wrapper