Difference between overloaded methods and overidden methods in Java
Overloaded Method | Overridden Method | |
---|---|---|
Arguments | Must change | Must not change |
Return type | Can change | Can’t change except for co-variant returns |
Exceptions | Can change | Can reduce or eliminate. Must not throw new or broader checked exceptions |
Access | Can change | Must not make more restrictive (can be less restrictive) |
Invocation | Reference type determines which overloaded version is selected. Happens at compile time. | Object type determines which method is selected. Happens at run-time. |
No comments:
Post a Comment