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.