nirjari patel wrote:If a reference is created of class type A, it can access members and methods available in class A.
That's a compile-time rule that determines which method signatures we're allowed to call, and which of the allowed signatures will be called at runtime. This looks only at the declared type of the reference (A in this case),
not at the object that the reference points to (B in this case).
Then, at runtime, we look at the actual class of the object (B in this case) and if that class overrides the method with the signature determined at compile time (and in this case it does), then we call that class's version. If not, we move up to its parent class, and then its parent, and so on.
This is the whole point of inheritance and overriding. It's why it exists.