在继承中,当为子类创建对象时,是否还为其超类创建了一个对象?

Nik*_*hil 3 java inheritance garbage-collection wrapper

  1. 在继承中,当为子类创建对象时,是否还为其超类创建了一个对象?
    我发现上述问题的答案是肯定的,它已经创建了.我对吗?

  2. 基于它是正确的假设,我解决了这个问题,我发现答案是4.我是对的吗?

  3. 长期是原始类型还是包装类?

问题:到达最后一个括号时,有多少对象符合垃圾回收的条件?

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;
}
}
Run Code Online (Sandbox Code Playgroud)

Abi*_*san 5

在继承中,当为子类创建对象时,是否还为其超类创建了一个对象?我发现上述问题的答案是肯定的,它的创建.我是对的吗?

不,它在创建子类对象时不会创建超类对象.子类对象将通过继承Super Class来拥有超类功能主义者.创建子类对象时,只会创建一个对象

是一个原始类型或包装类?

long是一种原始数据类型,Long是对应的Wrapper类.

问题:到达最后一个括号时,有多少对象符合垃圾回收的条件?

是的,将有6个对象,包括3个Long对象