1. If the subclass does not define a constructor method, then the parameterless constructor method of the parent class is invoked.
2. If a subclass defines a constructor method, whether it is a parameterless or a parameter, when creating an object of a subclass, the parent class is first executed without arguments, and then its own construction method is executed.
3. If a subclass invokes a constructor with a parameter in the parent class, it is possible to make the first statement in the subclass constructor by calling the constructor of the parent class required by the super (parameter).
4. If a constructor invokes another construction method in the class, you can use this (parameter) to cut the statement in the first article of the constructor method.
Plainly: The principle is to call the father first. (No on the default tone, there is a tune, anyway, as long as there is one on it.)
Package test; Class father{String s = "Run constructor method of Father"; public Father () {System.out.println (s);} public Father (St
Ring str) {s= str;
System.out.println (s); The class Son extends father{String s= "Run constructor method of Son"; the public Son () {//is actually here plus super (), and no Plus is the same Sy
Stem.out.println (s);
Public Son (String str) {this ();//This calls this () here to invoke the Son () of this class, because there is a super () in Son (), so it can't be added here.
s = str;
System.out.println (s);
The public Son (string str1, String str2) {super (str1+ "" +str2);//Because a superclass with parameter super ("---") has been called here, no arguments are automatically invoked.
s = str1;
System.out.println (s);
} public class MyClass9 {public static void main (string[] args) {Father obfather1 = new Father ();
Father obfather2 = new Father ("Hello Father");
Son obson1 = new Son ();
Son obson2 = new Son ("Hello Son");
Son Obson3 = new Son ("Hello Son", "Hello Father"); =============== Result: Run constructor method of Father Hello Father Run constructor method of Father run ConstrUctor the son Run constructor method of Father run constructor method of son hello son hello son hello Father Son