Method overloading vs overwriting method

Rewrite

Rewrite What does it mean? What are the rules?
As the name suggests is the method to re-write it again, and when to write it? When writing a subclass inherits the parent class method.

1. occurs between the parent class and subclass
The method name, parameter list, return type, must be the same. Referred to with the same name with a reference
3. Access modifiers limit must be greater than the access modifier is rewritten methods (details on accessing qualifier, another blog some more.) 4
non-checked exceptions: the overridden method can throw any unchecked exception, regardless of whether the method is overridden identified the anomaly
5, abnormalities: rewrite the new method must not throw checked exceptions, than to be rewritten or method declaration abnormalities broader checked exceptions
6, can not override flag is final, static methods

Overload

Overload Summary:
1, the list of parameters: the method must be overridden to change the parameter list
2, return type: may change the return type
3, modifier: modifier may vary
4, exception: can declare new or abnormal broader
5 , overload overload is a polymorphism of a performance
6, when overloaded, may be the same type of return value may not be identical. Unable to return typed overloaded function as the distinguishing criteria

Having said that, the interviewer that if I ask them, how can we answer it?

Overload is a class, the same method name but a plurality of different parameters of the method (and the return type, regardless of modifier). Rewrite is between parent and child class, subclass return type, method name, parameters, modifiers are consistent with the parent class method, in the case of inheritance can talk rewritten. The overloading can be used in any environment. Both are multi-state manner, except that it is implemented compile-time polymorphism, which polymorphism is achieved runtime. Overload no special requirements for the return type, it can not be differentiated according to the type of return.

Published 37 original articles · won praise 5 · Views 2016

Guess you like

Origin blog.csdn.net/chris__x/article/details/103265810