ket bhav wrote:When
B ref2 = (B) ref1;
reference ref1 will be cast to class B.
so B's method will be called.
And class B's
public int g() { return f(); }
will call method of class B.
if that might not exist then an only it will try to find from super class that is class A.
But in this case f() exist in class B so it will return 1.
dear ket, i think when you dide casting you are not pointing to that class see that below it can still access to sub class. i think what happens is it only limited to the methods which caseted class have