Difference Between Overloading and Overriding
Property | Overloading | Overriding |
Defination | Two methods are said to be overloaded if and only if both methods having the same name but different argument types | What ever methods parent has by default available to the child through inheritance.some times child may not satisfy with parent method implementation.Then child is allow to redefine that method based on its requirement.this process is called overriding |
Method Name | Must be Same | Must be Same |
Argument Types | Must be different(at least Order) | Must be same(including Order) |
Method Signature | Must be Same | Must be different |
Return Type | No Restriction | Must be same but this rule is applicable until 1.4 version only.From 1.5 onwards co-varrient return types are allowed |
privat.static and final methods | can be overloaded | can not be overridden |
Access modifiers | No Restriction | We can not reduced scope of access modifier but we can increase |
throws clause | No Restriction | If child class method throws any checked exception compulsory parent class method should throws the same checked exception are its parent otherwise we will get compile time errer but there are no restriction for unchecked exception |
Method Resolution | Always takes care by compiler based on reference type | Always takes care by JVM based on Run time object |
Also known as | Compile time polymorphism or static polymorphism or early binding | Runtime polymorphism,dynamic polymorphism or late binding |
No Comments Yet!!