Overloading: multiple functions with the same name but the same method name but different parameters
Note: 1. Different parameters means that there is at least one difference in parameter type, number of parameters, and parameter order.
2. Return values, exceptions, and access modifiers cannot be used as conditions for overloading (because for anonymous calls, ambiguity will occur, eg: void a () and int a(), if a() is called, ambiguity will occur)
3.The main method can also be overloaded
Override: The subclass rewrites the method of the parent class, requiring that the method name and parameter type are exactly the same (the parameters cannot be subclasses), the return value and exception are smaller or the same as those of the parent class (that is, they are subclasses of the parent class), and the access modifiers are smaller than those of the parent class. The parent class is larger or the same
Two same, two small and one big
Note: Subclass instance methods cannot override parent class static methods; subclass static methods cannot override parent class instance methods (an error occurs during compilation). In summary, methods cannot be cross-covered.
Hidden: When the parent class and the subclass have attributes or methods with the same name, the attribute or method of the parent class with the same name is missing in form, but actually still exists.
Note: When hiding occurs, whatever class the declaration type is, the properties or methods of the corresponding class will be called, and dynamic binding will not occur.
There is only one form of method hiding, that is, the same static method exists in the parent class and the subclass
Properties can only be hidden, not overwritten
Subclass instance variables/static variables can hide the instance/static variables of the parent class. In summary, variables can be cross-hidden.
The difference between hiding and covering:
Hidden attributes, after the subclass is coerced into the parent class, the attributes in the parent class are accessed.
The overridden method, after the subclass is forced to be converted to the parent class, still calls the method of the subclass itself.
Because coverage is dynamically bound and is subject to RTTI (run time type identification, runtime type inspection), hiding is not subject to RTTI. In summary, RTTI is only for coverage, not for hiding.
Special circumstances:
1. The properties modified by final can be hidden, but they cannot be assigned, that is, they cannot be assigned with =. It is said online that final properties cannot be modified. This statement is not accurate, because after a reference type variable is modified with final, it just cannot be modified. Points to other objects, but can change its own value. It can be tested with ArrayList. The final attribute can be initialized at runtime, but the initialization statement must appear.
2.Final modified methods cannot be overridden and can be overloaded
3. Final modified classes cannot be inherited
4. The private method implicitly adds final