Super generally appears in the construction method of subclasses.
The super statement must be written in the first line, and super is typically used to invoke the constructor of the parent class.
is to initialize the properties of the parent class so that the subclasses can use these properties.
After the subclass inherits, if you do not define your own properties or override your own methods, then when you create an object, the object calls the properties and methods in the parent class.
If you have one, use your own properties and methods.
Use super in a Java class to refer to the composition of the parent class, use this to refer to the current object , and if a class inherits from another class, when we new the instance object of the subclass (when invoking the constructor)
This subclass object will also create a parent class object super. How do you refer to the parent object inside? Using Super to refer to, this refers to a reference to the current object, and super is a reference to the parent object inside the current object. (Quoted from http://www.cnblogs.com/xdp-gacl/p/3635948.html)
The Super object inside each subclass's constructor has one copy of the properties and methods of the parent class.
1 Public classTest {2 Public Static voidMain (string[] args) {3b b =NewB ();//Output Ten4B B1 =NewB (11);//Output 05 }6 }7 8 classA {9 intAge ;Ten } One classBextendsA { A intAge//if the subclass does not define its own age attribute, then this.age points to the age that the parent inherits from, then the output will be ten . - PublicB () { - Super. age = 10;//assign the age of the parent class to a value of ten theSystem.out.println (Super. age); - } - - PublicBintAge ) { + This. Age = Age;//Age of the child class -System.out.println (Super. age);//The above construct is assigned, but this construct is not assigned to a value + } A}
(Study records, only for reference, follow-up will continue to amend the supplement.)
Java Foundation--super Keywords