1. Inheritance
Java only supports single inheritance, and a subclass can inherit only one parent class. A parent class can have more than one child class
Keyword: extends
Reduce duplicate code
2. The grammatical characteristics of inheritance
Class Student extends preson{
}
If the subclass inherits the parent class, and the child class adds its own member variable and member function on this basis
3. Instantiation of Subclasses
1. Procedure for generating subclasses
In the constructor of a subclass, the constructor of the parent class must be called (depending on the number of arguments passed in () and the type determined)
extends person{ int grade; Student () { Super(); System.out.println ("student constructor with no arguments"); } Student (int grade) { this(); }}
Super (); If you do not write, the compiler will add this sentence for you;
2. Calling the constructor of the parent class using Super
4. Replication of functions (override)
This (parameter) calls the constructor in this class this (). method, calling member functions in this class
Super (parameter) calls the constructor of the parent class ..... Ibid.
Replication is also known as overwriting or rewriting
1. Among the two classes that have a parent-child relationship
2. The parent class and subclass each have a function, the definitions of the two functions (return value type, function name and parameter list) are identical
5. Use super to call member functions in the parent class
Overloading is in a class, the replication is in two classes, with Super call the parent class function, and then add their own code;
Java Fundamentals Section----3. Inheritance, subclass instantiation, function replication