Java basics: subclass-parent class constructor relation, java Constructor
Premise: Parent class: Parent. java
Constructor: default constructor (without parameters) and parameter Constructor (when both parameters exist, you must create a constructor without parameters)
Example: public Parent () {}, public Parent (String param ){}
Subclass: Children. java
Constructor: default constructor (without parameters) and parameter Constructor (when both parameters exist, you must create a constructor without parameters)
Example: public Children () {}, public Children (String param ){}
1. Subclass display calls the parent class Constructor
(1) For example: public Children () {super () ;}, public Children (String param) {super (param );}
Display call. You can specify which constructor of the parent class to call. The keyword "super" must be written in the first line.
2. Subclass implicitly calls the parent class Constructor
(1) For example: public Children () {}, public Children (String param ){}
Implicit call. No parameter constructor is called by default. If no parameter constructor exists, the call must be displayed.
Note: Parent and Child classes refer to instantiated classes (that is, they do not involve interfaces or abstract classes)
The reason why super is written in the first line: the parent class must be constructed first, and the Child class must be constructed. Loading Mechanism problems.
3. this and super
This refers to the current class. this (), this (param) calls the class construction and needs to be placed in the first line, this. variable (variable)/method, etc., System. out. println (this) Description: The toString method is called by default, and the Object method is called or implemented by itself.
Super refers to the parent class. It is called only once in the subclass structure and only called in the last construction of the subclass this call.
Note: inaccurate or missing content. You are welcome to make positive comments ).