gpt4 book ai didi

java - 在继承中,为子类创建一个对象时,是否也为它的父类(super class)创建了一个对象?

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:10:38 24 4
gpt4 key购买 nike

  1. 在继承中,当为子类创建对象时,是否也为其父类(super class)创建对象?
    我发现上述问题的答案是肯定的,它已创建。我对吗?

  2. 基于正确的假设,我解决了这道题,我发现答案是4。我说得对吗?

  3. 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;
}
}

最佳答案

In inheritance, when an object is created for subclass, is an object also created for its superclass? I find the answer to the above question is yes, its created.Am I right?

不,创建子类对象时它不会创建父类(super class)对象。子类对象将通过从父类(super class)继承而具有父类(super class)功能主义者。创建子类对象时只会创建一个对象

Is long a primitive type or wrapper class??

long是原始数据类型,Long是对应的Wrapper类。

Question : When last brace is reached, how many objects are eligible for the garbage collection?

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

关于java - 在继承中,为子类创建一个对象时,是否也为它的父类(super class)创建了一个对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22556237/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com