In the following code, can someone explain to me the meaning of "A ba = (A)b;" and explain to me the outputs and how they are derived.
class A {
public void f(A a) { System.out.println("fa(A)");}
public void f(B b) { System.out.println("fa(B)");}
}
class B extends A {
public void f(A a) { System.out.println("fb(A)"); }
public void f(B b) { System.out.println("fb(B)"); }
}
public class TypeMeister {
public static void main(String[] args){
A a = new A();
B b = new B();
A ba = (A)b; //please explain
a.f(a);
a.f(b);
b.f(a);
b.f(b);
a.f(ba);
b.f(ba);;
ba.f(a);
ba.f(b);
ba.f(ba);
}
}
Thanks for your help.