Going by this rule the method INT in rectangle sounds to be the most specific one. But, when we compare the types we can see that a type of rectangle cannot be assigned to square without explicit type casting. So none of the methods are most specific and hence the "ambigious" error.
Hi Bishal:
Did you really mean to say CANNOT in above? I think it should be CAN.
My analysis is that int argument from within method call can be automatically casted to long. So the long method in square is a candidate. But the type of calling object (i.e. square) can be automatically casted to rectangle so int method in rectangle is also candidate. The issue is both of them are candidates by
single automatomatic cast. Hence ambiguity: which one to invoke?
If I change long type to byte, then int can not be automatically casted to byte, hence method in square is no more candidate, and I get no error message. At run time, int method in rectangle is invoked.
Thanks. Article you point to was very good.
Barkat
[ September 11, 2002: Message edited by: Barkat Mardhani ]