Detailed explanation of super keyword

Super attention points:
1. Super calls the construction method of the parent class, which must be the first of the construction method
2. Super must only appear in the method or construction method of the subclass!
3. Super and this cannot call the constructor at the same time!
The difference between super and this:
the object represented is different:
this: the object of the caller
super: the application of the parent class object.
Premise: this: whether inheritance can also use
super: it can only be used in the case of inheritance.
Construction method:
this(): the construction of this class
super(): the construction of the parent class

With a parameterized structure, if you want to use a parameterless structure, you must explicitly define a parameterless structure, otherwise it will overwrite the parameterless structure-
using the new keyword to report an error , the essence is to call the constructor, and initialize the value, and Allocated memory space

Guess you like

Origin blog.csdn.net/weixin_43815275/article/details/114435641