Selenium and Java

Monday, 8 June 2015

Java- Overloading Method


Overloading Method : 

              If a class have multiple methods by same name but different parameters, it is known as Method Overloading. Method overloading increases the readability of the program. It is also known as Static Polymorphism or compile time Polymorphism. 

Points to considered for overloading when method name is same:

  1. The number of parameters is different for the methods.
  2. The parameter types are different (like changing a parameter that was a float to an int). 
  3. Sequence of Data type of parameters. 
  4. Constructor in Java can be overloaded
  5. Overloading can take place in the same class or in its sub-class.

Points when overloading not considered :

  1. Just changing the return type of the method.  If the return type of the method is the only thing changed, then this will result in a compiler error.  
  2. Changing just the name of the method parameters, but not changing the parameter type.If the name of the method parameter is the only thing changed then this will also result in a compiler error

Example of Overloading : 

As explained earlier overloading done at compile time..
Overloading in same class..


















----------------------------------------------------------------------------------------------------

Overloading in Sub Class...



No comments:

Post a Comment