Edit
The first part of my answer was provided before the Java Testa constructor was added.
In Java code, you do not have the Testa constructor defined as in your C ++ code. This explains why only one B is printed in Java.
But even if you did it to make the code more equivalent:
public Testa() { this.Foo(); }
He will print
B B
Because in polymorphism, Java works even when calling a method from the constructor. But this is not a good idea, because the Testb object will still be uninitialized when the Foo method is called in Testb .
source share