[英]how can super refer to parent class object when we create a child class object?
When we create a child object, single object is created of child class which uses parent class variables.当我们创建子对象时,会创建使用父类变量的子类的单个对象。 this is my understanding.
这是我的理解。 I have read on many places that super refer to parent class object but here only one single object is created which inherits its members from parent class.
我在很多地方都读过 super 引用父类对象,但这里只创建了一个从父类继承其成员的对象。 Does a parent class object is implicitly created inside child one to which super refers to?.I dont exactly get how people have written and in which context that it refer to parent class object ?
父类对象是否是在 super 所指的子类中隐式创建的?我不完全了解人们是如何编写的以及它在哪种上下文中引用父类对象? when only child class object is created singly.
当仅单独创建子类对象时。
Have a look there for super meaning and use.看看那里的超级含义和用途。 https://docs.oracle.com/javase/tutorial/java/IandI/super.html
https://docs.oracle.com/javase/tutorial/java/IandI/super.html
Basically, you can see any object as an onion with the inner peel being Object and the outer one your object's class, with all the super classes in between.基本上,您可以将任何对象视为洋葱,内皮是 Object,外皮是您的对象的类,所有超类都在它们之间。 Each peel comes with its own attributes, class (overloaded, overridden, or new) and constructors (same) but the whole thing is a single object, each peel only seeing toward the inner core (except for overriden methods that are called to their outmost overriding peel - ie a method implementation that does not exist yet at the the considered peel declaration : see https://pretagteam.com/question/calling-an-overridden-method-superclass-an-calls-overridden-method )
每个果皮都有自己的属性、类(重载、覆盖或新的)和构造函数(相同)但整个事物是一个对象,每个果皮只看到内核(除了被调用到最外层的覆盖方法)覆盖果皮 - 即在所考虑的果皮声明中尚不存在的方法实现:请参阅https://pretagteam.com/question/calling-an-overridden-method-superclass-an-calls-overridden-method )
- If your method overrides one of its superclass's methods, you can invoke the overridden method through the use of the keyword super.
如果您的方法覆盖了其超类的方法之一,则可以通过使用关键字 super 来调用被覆盖的方法。
- You can also use super to refer to a hidden field (although hiding fields is discouraged).
您还可以使用 super 来引用隐藏字段(尽管不鼓励隐藏字段)。
- You can also use super(...) to invoke a specific superclass constructor (whether it is not public or need to be called with specific parameters)
您还可以使用 super(...) 来调用特定的超类构造函数(无论它是不是公共的还是需要使用特定参数调用)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.