|
Overloading (overload) |
Overwrite (override) |
| Concept |
Multiple methods of the same name that exist in the same class, with the same return value type and a different argument list |
A derived class redefined a method with the same name as a base class method, with the same return value type and argument list, except that the behavior is different |
where it appears
|
In the same class |
In different classes that have an inheritance relationship |
return value type
|
Same |
Same |
| Parameter list |
Different number of parameters or different parameter types |
Same |
| Characteristics |
Regardless of the return value type, focus only on the parameter list |
(1) A derived class method can assign the same or greater access rights as a base class method (2) A derived class cannot overwrite a base class method that is marked final (3) A derived class method can throw an exception, subclass exception, run-time exception, or error that is the same as a base class method, but cannot throw a new exception or superclass exception |
| Application Scenarios |
Perform the same task and just enter a different scene, using the same name method for easy reading |
Scenarios in which inheritance behavior needs to be redefined are often the primary purpose of using inheritance relationships
|
This article is from the "Youth is the experiment Lesson of Life" blog, please make sure to keep this source http://liusibo.blog.51cto.com/1382721/1921233
Comparing overloads and Overrides for Java methods