Differences between method overloading and method Rewriting
Answer 1: fundamental differences:
Rewriting (refactoring) is intuitive. Subclass covers the same parameters of the parent class and return values of the same name. The method called by subclass is only a rewriting method.
Overload, with the same name. Answer 2: 1. Heavy Load:
The method name is the same and the parameter list is different.
2. Rewrite:
It is also called overwrite. It refers to defining a method with the same name as the parameter list in the parent class in the subclass. The subclass inherits the methods of the parent class, And the rewrite is to re-define the methods inherited from the parent class and re-enter the code in the method.
Answer 3:
Override is a subclass method that overwrites the parent class. The method names and parameters must be the same.
Overload is two or more methods in the same class, with the same method name, but the parameters are different, and the method bodies are also different, the most common overload example is the class constructor. You can refer to the API help document to see the class constructor.
Answer 4:
1. Rewriting must be inherited, and overloading is not required.
2. The name of the method to be rewritten. The number of parameters is the same, the parameter type is compatible, the names of the methods to be reloaded are the same, and the parameter list is different.
3. The method modifier to be rewritten is greater than or equal to the parent class. The overload is irrelevant to the modifier.
4. Rewriting cannot throw General Exceptions not thrown by the parent class, and can throw runtime exceptions.