Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Confusion regarding Redifined Method calls

Former Member
0 Kudos

Out of curiosity I am asking this.

In Alternative 2 its mentioned that

Alternative 2

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

Effect

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

1 ACCEPTED SOLUTION

SuhaSaha
Advisor
Advisor
0 Kudos

Hello,

I guess you're confused between DEFINITION & IMPLEMENTATION

You should understand that the existence(or DEFINITION) of the method meth_name is searched for in the static type of cref, but as per the rules (of method re-definition) the IMPLEMENTATION is triggered based on the instance being referred to by cref.

Hope i'm clear.

BR,

Suhas

2 REPLIES 2

SuhaSaha
Advisor
Advisor
0 Kudos

Hello,

I guess you're confused between DEFINITION & IMPLEMENTATION

You should understand that the existence(or DEFINITION) of the method meth_name is searched for in the static type of cref, but as per the rules (of method re-definition) the IMPLEMENTATION is triggered based on the instance being referred to by cref.

Hope i'm clear.

BR,

Suhas

Former Member
0 Kudos

Thanks Suhas, I agree with you. I am aware of the difference between Defn and Implmn ... but didnt apply that here ..

Thanks once again