Sunday, June 30, 2019

Differences Between Method Overloading and Method Overloading in Java

Differences Between Method Overloading and Method Overloading in Java


Sl No Property Method Overloading Method Overriding
1 Method Names The Method names must be SAME for Method Overloading The Method names must be SAME for Method Overriding
2 Argument Types Argument Types must be different(At least the order must be different) The Arguments Type must be Same including the Order
3 Method Signatures The Method Signatures must be Different The Method Signatures must be Same
4 Return Types No Restrictions Must be same until 1.4V. From 1.5V onwards, Co-Variant Return types allowed
5 private, static, final Methods Can be Overloaded Cannot be Overridden
6 Access Modifiers No Restrictions The scope of the Access modifiers cannot be reduced but we can happily increase the scope(Private > Default > Protected > Public)
7 'Throws’ clause No Restrictions If the Child class method throws any checked Exception, the parent class method must compulsarily throw the same Checked Exception or its Parent’s Checked Exception. However, there is no restrictions for Unchecked Exceptions
8 Method Resolution Method Resolution is always taken care by Compiler based on referrenced Type Method Resolution is always taken care by JVM based on runtime Object.
9 Also known As (names) Also known as Compile Time Polymorphism or Static Polymorphism or Early Binding Also known as Run Time Polymorphism or Dynamic Polymorphism or Late Binding

No comments:

Post a Comment

Working with Pseudo elements in Selenium WebDriver

What are pseudo-elements? A CSS pseudo-element is a keyword added to a selector that lets you style a specific part of the selected elem...