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.

Popular posts from this blog

Resolve OutOfMemoryError With ExcelExport : Export Excel Utility with Apache POI Stream API (SXSSF)

Be-Aware of the Performance of the String Concatenation...

How To Resolve "Java compiler level does not match the version of the installed Java project facet." Issue in Eclipse, STS tool or Eclipse Based Tools