super() and this()

this: Refers to the current object (that is, yourself
) the role of this()

===================================================================

super: Refers to the parent class object, the job is to give the child class access to the members in the parent class

Call the parent class member variable: super. member variable

Call the non-static method of the parent class: super. method name (...)

Call the parent class constructor: super. Constructor (...)

Note:
1. Although the construction method of the parent class cannot be inherited to the subclass, it can be called by super
2. Because this uses the construction method of this class, and super calls the construction method of the parent class, both must be placed in the first line , So there can only be one of the two.
3. In the construction method of the subclass, super() will be defaulted to call the parameterless structure of the parent class, so in general, the parent class must provide a parameterless structure to enhance extensibility
4. If the subclass explicitly calls the parent class's construction method, then the default call does not exist

Guess you like

Origin blog.csdn.net/ExceptionCoder/article/details/107401052