Using ((Base)this).f();
instead of super.f()
in Derived.f() compiles fine but causes StackOverflowError in Runtime. Why?
class Base {
void f() {
System.out.println("Base.f()");
}
}
class Derived extends Base {
void f() {
((Base)this).f(); //instead of super.f();
System.out.println("Derived.f()");
}
}
public class MyTest {
public static void main(String[] args) {
new Derived().f();;
}
}