Given:
class Alpha {
public void foo() { System.out.print(“Afoo “); }
}
public class Beta extends Alpha {
public void foo() { System.out.print(“Bfoo “); }
public static void main(String[] args) {
Alpha a = new Beta();
Beta b = (Beta)a;
a.foo();
b.foo();
}
}
What is the result?
A.
Afoo Afoo
B.
Afoo Bfoo
C.
Bfoo Afoo
D.
Bfoo Bfoo
E.
Compilation fails.
F.
An exception is thrown at runtime.
D
D