-2

I am new to Java and trying to learn Method Overloading and got bit confused. Here is my program

class Adder {
    static void add(int a, int b) {
        System.out.println("a method invoked");
    }

    static void add(long a, int b) {
        System.out.println("b method invoked");
    }
}
class TestMethodOverloading {
    public static void main(String[] args) {
        Adder.add( 9223372036854775807,12);
    }
}

I am getting compiler error saying

java: integer number too large

I am confused why method add with parameter long is not called here?

Ganesh Babu
  • 3,590
  • 11
  • 34
  • 67
  • It is not a problem with overloading, but how you create `long` literal. Without `L` suffix your number represents `int` but that number is out of `int` range. – Pshemo Jun 13 '20 at 06:31

1 Answers1

2

You missed the L at the end of the number to denote it's a long.

loic
  • 151
  • 1
  • 4