|
Override: overwrite, which overwrites a method and overwrites it for different purposes. What we are most familiar
It is the implementation of the interface method. In the interface, the method is generally declared, and we need
All methods that implement the interface declaration. In addition to this typical usage, we may also overwrite
The method in the parent class.
Pay attention to the following points when overwriting:
1. the logo of the covered method must match the logo of the covered method to achieve the coverage effect;
2. The returned value of the overwritten method must be the same as that of the overwritten method;
3. The exception thrown by the overwriting method must be the same as that thrown by the overwriting method, or its subclass;
4. The method to be overwritten cannot be private. Otherwise, a new method is defined in its subclass and not overwritten.
Overload: overload. It means that we can define methods with the same name and distinguish them by defining different input parameters.
Then, the VM selects the appropriate method for execution based on different parameter styles. To
Note the following:
1. You can only use different parameter styles when using overload. For example, different parameter types, different parameter numbers, and different parameter Shun
(Of course, several parameter types in the same method must be different;
2. It cannot be overloaded by access permission, return type, or thrown exception;
3. The method exception type and quantity do not affect the heavy load;
4. For inheritance, if a method has a priavte access permission in the parent class, it cannot be overloaded in the subclass, as shown in figure
If it is defined, it only defines a new method and will not achieve the effect of overloading. |