JAVA
"B" overrides "foo()", but invokes "super.foo()". Because the overridden "foo()" in "A" is invoked by an instance of "B", the "this" reference is pointing to "B", not "A". Therefore, when I create another instance of "this", another "B" object is created.
public class Main {
public static void main(String[] args) {
new B();
}
static class A {
void foo() {
try {
this.getClass().newInstance();
} catch(Exception e) {
e.printStackTrace();
}
}
}
static class B extends A {
B() { foo(); }
void foo() { super.foo(); }
}
}