Pass long parameters to overloading method : Method Overloading « Class Definition « Java Tutorial






It is legal to have these two methods in the same class.

public class MainClass {
  public int printNumber(int i) {
      return i*2;
  }

  public long printNumber(long i) {
      return i*3;
  }
  public static void main(String[] args) {

  }

}

printNumber(3) will invoke this method:

public int printNumber(int i)

To call the second, pass a long:

printNumber(3L);








5.5.Method Overloading
5.5.1.Method Overloading
5.5.2.Using Method Overloading
5.5.3.Pass long parameters to overloading method
5.5.4.Primitives and overloading
5.5.5.Overloading based on the order of the arguments
5.5.6.Demonstration of both constructor and ordinary method overloading
5.5.7.Using overloaded methods to print array of different types
5.5.8.Methods with differing type signatures are overloaded - not overridden.