Study notes: java inheritance

 Why should there be inheritance?
 When the same attributes and behaviors exist in multiple classes, extract these contents into a single class, so multiple classes do not need to define these attributes and behaviors, as long as they inherit that class.
 The multiple classes here are called subclasses, and the single class is called the parent class (base class or super class). It can be understood as: "subclass is a parent class"
 Class inheritance grammar rules:
class Subclass extends Superclass{}
 Java only supports single inheritance and does not allow multiple inheritance
 Definition: In the subclass, the parent class Transformation of inherited methods is also called method resetting and overwriting. When the program is executed, the method of the subclass will override the method of the parent class.
 Requirements:
 The overridden method must have the same method name, parameter list, and return value type as the overridden method.
 The overridden method cannot use stricter access permissions than the overridden method.
 The overridden and overridden methods must be static or non-static at the same time
. The exception thrown by the subclass method cannot be greater than the exception of the overridden method of the parent
class. Use super in the Java class to call the parent class. The specified operations in:
 super can be used to access the properties defined in the parent class
 super can be used to call the member methods defined in the parent class  super can be used to call the constructor of the parent class in the
subclass construction method
 Note:
 Especially when When there are members with the same name in the child and parent class, super can be used to distinguish
 The traceability of super is not limited to the direct parent category
.

Guess you like

Origin blog.csdn.net/qq_44909275/article/details/105197340