posted 17 years ago
As Ian has mentioned already,
for
ob.sum(10,20)
the compiler is passed with implied 2 int primitives. Therefore, the compiler knows which method to call, which is the
sum(int a, int b)
However, for the
ob.sum(x,y);
you passed an int and and Integer. The compiler doesnt know which of the 2 methods to call:
sum(int a, int b)
or
sum(Integer a ,Integer b)
If you are still confused, try think like a compiler. If you are the compiler, how you know which of the 2 overloaded methods would you call if you are given
ob.sum(x,y)
?