1. Overloading: You can have multiple functions in the same class, the function name is the same but the parameter list (number of arguments, parameter type, parameter order) is different, you cannot define overloading by method return value type, access permission, and throw exception.
2. Rewrite: the "override (overwrite)" concept exists in an inheritance relationship, and subclasses can inherit methods from the parent class without having to edit them individually, which provides ease of use. However, in some cases, subclasses do not want to inherit the method of the parent class intact, but want to make certain changes, this need to adopt the method of rewriting.
Methods that inherit from a parent class can be overridden in a subclass as needed
The overridden method and the overridden method must have the same method name, argument list, and return type
The overriding method cannot use more restrictive access than the overridden method
3. Difference:
1). Override Features
1, the mark of the method of covering must match with the mark of the method that is covered completely, can reach the effect of coverage;
2. The return value of the overridden method must be the same as the return of the overridden method;
3. The exception that is thrown by the overridden method must be the same as the exception thrown by the overridden method, or its subclass;
4. The overridden method cannot be private, otherwise only a new method is defined in its subclass, and it is not overwritten.
2). Overload features
1. You can only pass different parameter styles when using overloads. For example, different parameter types, different number of parameters, different parameter order (of course, several parameter types within the same method must differ, such as can be fun (int, float), but not fun (int, int));
2, can not be overloaded by access rights, return type, thrown exception;
3, the method of the exception type and number will not affect the overload;
4, for inheritance, if a method in the parent class is the access permission is PRIAVTE, then it can not be overloaded in the subclass, if defined, but also only defined a new method, but not to achieve the overloaded effect.
Overloading and rewriting in Java