tags:

views:

29

answers:

0

If dataValue1 and dataValue2 are id variables, the statement result = [dataValue1 add: dataValue2]; causes the compiler to generate code to pass the argument to an add:method and handle its returned value by making assumptions.

At runtime,the Objective-C runtime system will check the actual class of the object stored inside dataValue1 and select the appropriatemethod from the correct class to ex- ecute.

However, in a moregeneral case, the compiler might generate the incorrect code to pass arguments to a method or handle its return value.

This would happen if one method took an object as its argument and the other took a floating-point value, for example.

Or if one method returned an object and the other returned an integer, for example.

If the inconsistency between two methods is just a different type of object (for example,the Fraction’s add: method takes a Fraction object as its argument and returns one, and the Complex’s add:method takes and returns a Complexobject ), the com- piler will still generate the correct code because memory addresses (that is, pointers)are passed as references to objects anyway.

I am not getting above paragraph, can any one explain me using example code or diagrams?