Can anybody explain Overloadnig vs overridding with example.
Abhay Ojha
Select an image from your device to upload
Difference between Overriding and Overloading
Overriding is the example of run-time polymorphism and
Overloading is the example of compile-time polymorphism.
Overriding
¦The return type must exactly match that of the overridden method.¦The access level must not be more restrictive than that of the overridden method.¦The access level can be less restrictive than that of the overridden method.¦The overriding method must not throw new or broader checked exceptions than those declared by the overridden method. ¦The overriding method can throw narrower or fewer exceptions. Just because an overridden method “takes risks” doesn’t mean that the overriding subclass’ exception takes the same risks. Bottom line: An overriding method doesn’t have to declare any exceptions that it will never throw, regardless of what the overridden method declares.¦You cannot override a method marked final.¦If a method can’t be inherited, you cannot override it.
Overloaded method
¦Overloaded methods must change the argument list.¦Overloaded methods can change the return type.¦Overloaded methods can change the access modifier.¦Overloaded methods can declare new or broader checked exceptions.¦A method can be overloaded in the same class or in a subclass.
http://kalitinterviewquestions.blogspot.com/