java2db

What is the difference between overriding and overloading in java



Frequently we are using overriding and overloading concepts in the real time. These are very essential to develop software applications .

Below listed the difference between overriding and overloading .

overriding and overloading Overriding :
overriding and overloading  Two or more methods having the same name, parameters and return type (same signatures).
overriding and overloading  Parameters number and type are same .
overriding and overloading  Return type must be same .
overriding and overloading  Overriding only possible in inheritance.
overriding and overloading  super key word help’s us to call the base class method.
overriding and overloading  JVM decides which method is called depending on the data type (class) of the object used to call the method.
overriding and overloading  Method overriding is code replacement.

 

overriding and overloading Overloading :
overriding and overloading  Two or more methods having the same name,different parameters and same or different return type(different signature).
overriding and overloading  The number or type or order of the parameters should be different.
overriding and overloading  Return type may or may not be the same type, it wont show any effect.
overriding and overloading  Overloading can possible in the same class,inheritance and interface.
overriding and overloading  No need to call super key word in case of overloading.
overriding and overloading  JVM decides which method is called depending in the difference in the method signatures.
overriding and overloading  Method overloading is code refinement.

 

Example for overriding :

Execution Result :

overriding and overloading  In the above example height()  method overridden in the derived class.

 

Example for overloading :

Execution Result:

  overriding and overloading The above example calculate() method Overloaded with different method signature.

 




Related Posts :
   [will not be published]



^ <