public class A {
public void x()
{
System.out.println("A");
}
}
public class B extends A {
public void x()
{
System.out.println("B");
}
}
B b = new B();
A a = (A) b;
a.x();
This code prints "B". Could you tell me why? I thought that it would print "A".
Bpolymorphismin your headline. Google it and you will find tons of tutorials on that topic.