Thursday, September 25, 2014

Rules for Overloading the Method in Java

  1. You can overload a method by changing its signature. method signature is made of number of arguments, type of arguments and order of arguments.
  2. Return type is not a part of method signature, so changing method return type means no overloading unless you change argument with return type.
  3. A method can be overloaded in the same class or in a subclass. if class A defines a display(float i) method, the subclass B could define a display(String s) method without overriding the super-class version that takes an int. So two methods with the same name but in different classes can still be considered overloaded, if the subclass inherits one version of the method and then declares another overloaded version in its class definition.