class A { int x = 1; void f() { System.out.printf("A.f(), x is %d\n",x); } } class B extends A { int x = 2; void f() { System.out.printf("B.f(), x is %d, super.x is %d\n",x,super.x); } void g() { super.f(); } } public class runtype { public static void main(String[] args) { A obj = new B(); obj.f(); ((A)obj).f(); // still uses B.f() // if this were perl, you can say "bless obj A", and change its type! //obj.g(); // error, static type doesn't contain g ((B)obj).g(); // calls A.f(), so A.f() still "in" object. System.out.printf("1/3 is %.9f\n",1/3.0); } } /* prints B.f(), x is 2 B.f(), x is 2 */