Sunday, 22 February 2015

What are the differences between method overloading and method overriding?



Overloaded Method
Overridden Method
Arguments
Must change
Must not change
Return type
Can change
Can’t change except for covariant 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 runtime.

No comments:

Post a Comment