One.
Now think about why you have super () and why you want to access the parent class.
For the problems in, the further extension is why there is a subclass instantiation?
After the subclass inherits the parent class, it creates a relationship that has some properties and behaviors of the parent class.
As an example:
, some attributes are defined in the parent class, and the properties are initialized with constructors. If the subclass does not access the parent class, and if the subclass new object only calls its own, does not access the parent class's constructor, then the child class gets the NUM value is 0 (first, the subclass inherits the parent class's properties, then the property does not pass the parent class's initialization constructor, and the result is 0). This is inappropriate because the parent class itself initializes its own properties, so when the subclass takes the parent thing, it first looks at how the parent class initializes its own stuff. Your initialization is over, I'll take it directly. So accessing the parent class constructor becomes necessary.
When the subclass is initialized, the subclass object is established in memory space, and NUM and the subclass of the parent class are displayed in the memory space. Then it knows how the parent class initializes the Num.
You take people's things, is not first to look at, people how to their own things to initialize. That is why the subclass must access the parent class constructor.
In order to complete this necessary action, a super (), statement is added to the constructor of the subclass.
The core of the instantiation process is super (), why does it have an instantiated appearance? The problem arises from the inheritance of the child-parent class, which creates the object with the subclass and initializes it when the object is created. Because it is an inheritance relationship, the photon class initialization is definitely not possible, and there must be initialization of the parent class. This explains why there is the instantiation of subclasses and the existence of super (). Also, the super () statement can directly direct the initialization of which constructor of the parent class.
There is a small episode here, and the conflict comes with it.
In the previous study, the description class has the existence of this (), do not look at the parent class, so write is correct. This () is the Zi () constructor initialization called in this class, and now ask the Zi (int x) constructor for super ()?
Before this () is to put in the first line, now talk about inheritance, super () also put on the first line, then this is not a conflict?
The right thing to say is that there is no super (). But without super (), what's the point of inheriting the parent class?
Look closely at the following, the process is this: first new Zi (6), when you create a new object, to initialize. Called Zi (int x), in this constructor, the first sentence is this (), and there is no super () statement. Because of this () relationship, before Zi (int x) is initialized, we call the initialization of this type of NULL parameter first, in the constructor of Zi (), the first sentence is super ().
There must be one access to the parent class, at least one, no super () initialization. Subclass initialization is not possible without the help of the parent class.
Look above, if there is this (3) in Zi (), then it has no super () statement, only this (3), as if both constructors in the subclass do not have a super () statement. In fact, there is a problem with this writing. When you create a new object, call the Zi (int x) function, execute this () in the Zi (int x) function, call Zi () initialization, and then execute this (3) in Zi (), which is called back to the Zi (int x) function, so that it falls into a dead loop.
Here's a question, why is there a super (3) statement in Zi ()? Does it mean that this () and super () can only have one at the beginning of a sentence,
For child-parent classes that have been developed with inheritance, any class will have implicit sentences in the following, implicit default functions with implicit super () statements and Renturn return statements in the function.
Constructors also carry permissions, and if the class is preceded by public, that is, public class demo{}, the constructor also has public. Class is public, and its constructors have to go public. If the class does not have public, then it does not need public.
In the above, there is a small doubt, the demo class does not inherit, the inside of the constructor where the super () statement?
Java is an object-oriented language that provides n objects that, whatever their functions, are extracted as objects and eventually extracted into a class named object. Any object you create is a subclass of object, either direct or indirect. Class Demo does not write after extends Object,demo is also a subclass of object.
Preliminary understanding of java--nineth-inheritance-constructors in child-parent classes-instantiation of subclasses-details