I'm running over this problem while working with the following inheritance and JDK 14
interface A {
default void a() {
System.out.println("default a");
}
default void b() {
System.out.println("default b");
}
}
class AImp implements A {
@Override
public void a() {
System.out.println("a from AImp");
}
@Override
public void b() {
System.out.println("b from AImp");
this.a();
}
}
class B extends AImp {
@Override
public void a() {
System.out.println("a from B");
}
@Override
public void b() {
System.out.println("b from B");
super.b();
}
}
when I run
B b = new B();
b.b();
console gives
b from B
b from AImp
a from B
How come the keyword this in the AImp is referencing the instance of class B?
Am I being confused with something here?
Thank you for spending time.