Dilshad, I think you are right.
I have just modified your program to proove your statement.
// prog 1.
public class Test7
{
public void method(Test9 s)
{
System.out.println("Test9 Version");
}
public void method(Test8 I)
{
System.out.println("Test8 Version");
}
public static void main(String args[])
{
Test7 question = new Test7();
question.method(null);
}
}
class Test8{}
class Test9 extends Test8{}
Above program's output is: Test9 Version
//progr 2
public class Test7
{
public void method(Test10 s)
{
System.out.println("Test10 Version");
}
public void method(Test9 s)
{
System.out.println("Test9 Version");
}
public void method(Test8 I)
{
System.out.println("Test8 Version");
}
public static void main(String args[])
{
Test7 question = new Test7();
question.method(null);
}
}
class Test8{}
class Test9 extends Test8{}
class Test10 extends Test8{}
Above program gives compilation error, saying: Reference to method is ambiguous.
---Narsimha
Above
Originally posted by Dilshad Syed:
So, is it safe to assume that:
In case of overloaded methods, if there is ambiguity at runtime, the JVM will ALWAYS call the overloaded method with the argument of the subclass
What would happen in the above example if there was no relationship between the arguments(String and Object) and both could still accept the same parameter(null)?