Rules of Method Overloading in Java...



Rules of Method Overloading...
  1. First rule to overload a method in Java is to change method signature. Method signature is made of number of arguments, type of arguments and order of arguments if they are of different types. You can change any of these or combinations of them to overload a method in Java. For example, in following code, we have changed number of arguments to overload print() method in Java :
  2. Return type of method is not part of method signature, so just changing the return type will not overload a method in Java.  In fact, just changing the return type will result in compile time error as "duplicate method X in type Y. Here is a screenshot of that error in Eclipse 

Comments