1 Inheritance: Java is a single inheritance, meaning that a class can only inherit from one class (The inherited class is called the "base class" of the parent Class), and the inheritance in Java uses the extends key
2. When a subclass object is generated, Java defaults to calling the parent class's constructor without arguments, and then executes the constructor to generate the parent class object. Next, the object of the subclass is called, "to generate the object of the subclass, you first need to generate the object of the parent class, and there is no child class object without the parent class object." Say: No father, no children.
3.super Keyword: Super represents a reference to a parent class object
4. If a subclass uses super () to display a corresponding constructor method that calls a parent class and no longer looks for a parent class with no arguments, the same as this, super must be executed as the first execution of the method, and no other executable statement can precede it.
5. Three points on inheritance:
1. There is a parent class, and subclasses have
2. No parent class, subclasses can increase
3. The parent class has, subclasses can change
6. Considerations regarding Inheritance
1. Construction methods cannot be inherited
2. Methods and properties can be inherited
3. Constructor methods for subclasses implicitly call the parent class's constructor without arguments
4. When the parent class does not have a constructor method with no arguments, the subclass needs to use super to explicitly call the parent class's constructor, and super refers to a reference to the parent class
The 5.super keyword must be the first line of the construction method statement
7. Method overrides are also called Overwrite: the subclass is the same as the method return type of the parent class, the method name is the same as the parameter, so we say that the child class and the parent class's methods constitute an overriding relationship
8. Method overrides the relationship between method overloads: Overloading two or more methods that occur inside the same class, overriding the relationship between the parent class and the Violet
9. When two methods form a rewrite relationship, The Run method of the parent class can be called in the subclass method through Super.run (), where the Super.run () method does not have to be placed in the first line of the statement, because the parent class object is already constructed, the run method of the parent class is called first, or the run method of the surrogate subclass is implemented according to the logic of the program.
Class animal{
public void Run () {
System.out.println ("Animal is running");
}
}
Class Dog extends animal{
public void Run () {
Super.run ();
System.out.println ("Dog is Running");
}
}
public class InheritenceTest2 {
public static void Main (string[] args) {
TODO auto-generated method stubs
Dog dog = new Dog ();
Dog.run ();
}
}
9. When defining a class, if the parent class of the class is not explicitly developed, then the column inherits the Java.lang.Object class (a class that the JDK provides Oject class is the direct or indirect parent of all classes in Java)
Java Object-oriented inheritance