Method Rewrite rules:
The parameter list and the return value type must be the same as the overridden method
Access permissions cannot be lower than the overridden methods in the parent class. For example, if a method of the parent class is declared public, overriding the method in the subclass cannot be declared as protected
The Member method of the parent class can only be overridden by its subclasses
A method that is declared final cannot be overridden
| static methods can also be inherited However, static methods cannot be overridden |
| can |
| : parent class name . static method Name (superclassnamestaticmethodname) call hidden |
| static method |
Subclasses and parent classes in the same package, subclasses can override all methods of the parent class, except for the methods declared private and final.
Subclasses and parent classes are not in the same package, subclasses can only override non-final methods that are declared public and protected by a parent class
The overridden method can throw any non-mandatory exception, regardless of whether the overridden method throws an exception. However, the overridden method cannot throw a new mandatory exception, or a more extensive mandatory exception than the overridden method declaration, or vice versa.
The construction method cannot be overridden.
If you cannot inherit a method, you cannot override this method
Method overload rules:
Overloading (overloading) is a class in which the method name is the same and the parameters are different. Return types can be the same or different
The overloaded method must change the parameter list (the number of parameters or the type or order is different);
Overloaded methods can change the return value type
Overloaded methods can change the access modifier
Method can be overloaded in the same class or in a subclass
overriding and overloading of Java methods