Question 0-7

Describe the process that Smalltalk goes through in looking up a method when a message is sent to an object A. (Be sure to allow for the fact that the method may have been inherited by a superclass.)

Solution

Each object has a reference to the object representing its class. Suppose A's reference is to B. The interpreter will go to B from A and ask B whether its method dictionary contains the requested method. If not, then from B it gets the class object representing B's superclass, and it asks it whether it contains the requested method. It continues this up the hierarchy, stopping when the requested method is found (or if it exhausts the hierarchy with no success).

Back to Exam 0