Running this code:
class A {
public int x;
public A() {
function();
}
public void function() {
this.x = 20;
}
public void printhey() { System.out.println("Hey"); }
}
class B extends A {
public B() {
super();
printhey();
}
public void function() {
this.x = 50;
}
}
public class tmp {
public static void main(String[] args) {
System.out.println((new B()).x);
}
}
prints out:
Hey
50
Who sets up the VTBL? in A
's constructor, function
is already set to be B. But in B
's constructor, printhey
is set up to be A's.