I have these two classes and I want to know why the output is A, B, and B.xxx. Can someone explain why it is not A.xxx when it is casted?
Here are my two classes and the main method:
public abstract class A {
public A() {
System.out.println("A");
}
public void xxx() {
System.out.println("A.xxx");
}
abstract void yyy();
}
public class B extends A {
public B() {
System.out.println("B");
}
public void xxx() {
System.out.println("B.xxx");
}
public void yyy() {
System.out.println("B.yyy");
}
}
public class ClassRunner {
public static void main(String[] args) {
B b2 = new B();
((A)b2) .xxx();
}
}