Inner和Subclass之间的创建差异

huangapple go评论79阅读模式
英文:

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

也许可以用一张图片/类比来表示这两种关系:

Inner和Subclass之间的创建差异

即:

  • janeDoe 这个子类实例只是一个对象,但它同时是两种类型的一个实例。

  • johnDoe,内部类的实例,与外部类实例 janeDoe 是不同的。它们之间有着紧密的联系,在它们之间,它们知道如何彼此使用。

英文:

Maybe a picture/analogy to represent the two relationships:

Inner和Subclass之间的创建差异

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 from janeDoe, the outer class instance. They have a very close link and, between them, they know how they use each other.

huangapple
  • 本文由 发表于 2020年10月7日 13:00:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/64237489.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定