1. Definition of inheritance:
When multiple classes have common content, you can extract the common content into a new class, and the new class and multiple classes form an inheritance relationship.
After the subclass inherits the parent class, it automatically owns all the non-private properties and functions of the parent class.
2. Considerations of succession (characteristics):
(1) Java only supports single inheritance, does not support multiple inheritance, but can be multi-layered inheritance (transitive);
(2) All classes inherit directly or indirectly from the object class, and the object class has no parent class;
(3) The construction method cannot be inherited;
3. Method overrides:
Definition: Return value type, method name, parameter list and parent class are identical, and the access modifier of the subclass method is the same as the parent class, or wider.
Modifier permission comparison: public protected default Private
When a subclass inherits the parent class, it automatically has all the non-private properties and functionality of the parent class, but the subclass considers the parent class method not good enough and is not strong enough to override the parent class method according to its own logic.
4. Considerations for method Rewriting:
(1) Private methods in the parent class cannot be overridden
(2) When a subclass overrides a parent class method, the access permissions must be the same or wider than the parent class
(3) Parent class static methods, subclasses must also be overridden by static methods
(4) The method that the parent class is final decorated cannot be overridden
(5) You can use @override to check if the method is overridden