I am not sure if i have wrong idea about double dispatch. But this is what i thought:
class A{
void testA( B obj ){
System.out.println( "A-Parent" );
obj.testB();
}
}
class AChild extends A{
void testA( B obj ){
System.out.println( "A-Child" );
obj.testB();
}
}
class B{
void testB(){
System.out.println( "B-Parent" );
}
}
class BChild extends B{
void testB(){
System.out.println( "B-Child" );
}
}
class Launcher{
public static void main(){
A objA = new AChild();
B objB = new BChild();
objA.testA(objB);
}
}
What I expected:
A-Child
B-Parent
Actual output:
A-Child
B-Child // How ???????
I thought Java resolves objA to Achild correctly during run time while the parameter is resolved during compile time to B, due to Javas Single diapatch. please tell me where i got it wrong?