Difference between Method Overloading and Method Overriding
- Method Names: - In Overloading method name should be same, And Even In Overriding method name should be same.
- Argument Type: - In Overloading, argument type must be different (at least the order of arguments), But in the Overriding argument type must be same.
- Method Signature: - In Overloading, method signature must be different, But in the Overriding method signature must be same.
- Return Type: - In Overloading, there is no restriction on the return type, But in Overriding return type must be same until 1.4 v, But from 1.5v onwards co-variant return type is allowed.
- private, static, final modifiers: - In Overloading, these modifiers consist method can be overloaded, But in Overriding these modifiers consists method can be overridden.
- Access modifier: - In Overloading, there is no restriction with the access modifier, But in Overriding, we can't reduce the scope of the modifier but we can increase the scope.
- throws clause: - In Overloading, there is no restriction with the throws clause, But in Overriding if child class method throws any checked exception compulsory parent class method should throw the same checked exception or its parent but no restriction with the unchecked exceptions.
- method resolution: - In Overloading, method resolution is always taken care by the compiler based on the reference type, But in the Overriding method resolution is always taken care by JVM based on runtime object.
- It is also known as - Overloading is also known as compile-time polymorphism or static polymorphism But Overriding is also known as run-time polymorphism or dynamic polymorphism.
Upload post on exception handling also..
ReplyDeletecoming soon...
ReplyDelete