Difference Between Overloading and Overriding in Java
Hello once again we discuss about difference between overloading and overriding in java. This is frequently asked in any interview question.
Overloading occurs when two or more methods in one class have the same method name but different parameters.
Overriding means having two methods with the same method name and parameters (i.e., method signature).
Overloading occurs when two or more methods in one class have the same method name but different parameters.
Overriding means having two methods with the same method name and parameters (i.e., method signature).
- Overloading happens at compile-time while Overriding happens at runtime
- overloading is being done in the same class while for overriding base and child classes are required.
- Method overloading is performed within class. Method overriding occurs in two classes that have IS-A (inheritance) relationship.
- In case of method overloading, parameter must be different. In case of method overriding, parameter must be same.
- Overloaded method are fast as compare to Overridden method in Java
- You can not override static, final and private method in Java but you can overload static, final or private method in Java.
- Overloaded method in Java is bonded by static binding and overridden methods are subject to dynamic binding.
No comments :
Post a Comment