In this code
class Parent {
void show() {
System.out.print("parent");
}
Parent a() {
return this;
}
}
class Child extends Parent {
void show() {
System.out.print("child");
}
public static void main(String arg[]) {
Parent a = new Child();
Parent b = a.a();
b.show();
}
}
What does return this;
do? b.show()
is invoking the child method show. So does this
return reference to its child class? If not then how is the show()
method of child being called?