Skip to Content
Former Member
Oct 19, 2011 at 05:14 AM

Confusion regarding Redifined Method calls


Out of curiosity I am asking this.

In Alternative 2 its mentioned that

Alternative 2

... cref->(meth_name) ... .


This form is possible for all visible methods of objects. cref can be any class reference variable that points to an object that contains the method specified in meth_name. This method is searched for first in the static type, then in the dynamic type of cref

So, If a object OBJ_C1 of type ref to Superclass C1 calls a method say M1 which is redifined in child class C2.

then if OBJ_C1 is pointing to instance of C2, and we use OBJ_C1->('M1'), As per Alternative 2, First the search for M1 is made in the static type of Object OBJ_C1 which is M1 of class C1 and then in the subclass C2. so why then Dynamic call

OBJ_C1->('M1') triggers the redifined method as if we have called it like OBJ_C1->M1 (not Dynamically)

Note: OBJ_C1->M1 does not trigger dynamic search as its a static call.

Whereas OBJ_C2->('M1') triggers SEARCH for M1 in static type and then in dynamic type if not found in static Type