英文:
Difference in creation between Inner and Subclass
问题
我注意到制作 内部 类需要 外部 类的实例。但是要创建 子类,我们也需要 父类 的实例。
如果有的话,它们之间的区别是什么?严格来说是在创建方面,而不是工作方式。我能这样想象吗:有一个 父类 对象,里面有一个 子类 对象,就像 内部 类对象位于堆中的 外部 类对象内一样?我离这个想法有多近?
英文:
I noticed that to make Inner class we need instance of Outer class. But to also make a Subclass, we need Parent class to create instance, as well.
What is difference between them if there is some? Strictly speaking in creation and not how they work. Can I picture it: there is object of Parent and inside it is Child object, same as Inner class object is inside Outer class's object in heap? Am I any close to this?
答案1
得分: 2
也许可以用一张图片/类比来表示这两种关系:
即:
-
janeDoe
这个子类实例只是一个对象,但它同时是两种类型的一个实例。 -
johnDoe
,内部类的实例,与外部类实例janeDoe
是不同的。它们之间有着紧密的联系,在它们之间,它们知道如何彼此使用。
英文:
Maybe a picture/analogy to represent the two relationships:
i.e.:
-
janeDoe
the subclass instance is just one object, but it's both types in one instance. -
johnDoe
, the inner class instance, is distinct fromjaneDoe
, the outer class instance. They have a very close link and, between them, they know how they use each other.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论