J
Juergen
Hi,
can somebody please explain to me, why the output of the code below is
test(A)
test(A)
instead of
test(A)
test(B)
which I had expected?
It seems, Java only uses the dynamic type information for calling an
object's methods, but not if the class is a parameter of a third
class's methods.
Why is this so?
Thanks,
Juergen
package overloading;
public class Test
{
public class A {}
public class B extends A {}
private void test(A a)
{
System.out.println("test(A)");
}
private void test(B b)
{
System.out.println("test(B)");
}
public static void main(String[] args)
{
Test t = new Test();
A a = t.new A();
A b = t.new B();
t.test(a);
t.test(b);
}
}
can somebody please explain to me, why the output of the code below is
test(A)
test(A)
instead of
test(A)
test(B)
which I had expected?
It seems, Java only uses the dynamic type information for calling an
object's methods, but not if the class is a parameter of a third
class's methods.
Why is this so?
Thanks,
Juergen
package overloading;
public class Test
{
public class A {}
public class B extends A {}
private void test(A a)
{
System.out.println("test(A)");
}
private void test(B b)
{
System.out.println("test(B)");
}
public static void main(String[] args)
{
Test t = new Test();
A a = t.new A();
A b = t.new B();
t.test(a);
t.test(b);
}
}