super semantics and the differences with self
Take 5 min and write the definition of super
super represent?super?
A new bar
> ...
B new bar
> ...
C new bar
> ...
A new bar
> 10
B new bar
> 20
C new bar
> 100
Evaluation of aC bar
aC's class is Cbar in CB - bar is foundbar is executedbar is sent to supersuper is aC but lookup starts in Abar is found in A and executedfoo is sent to aCfoo is found in Csuper refers to the receiver of the message (just like self)super expression
We don't know which foo method bar refers to
B>>foo refers to A>>foosupersuper looks for the method in the superclass of the receiver's class
In reality it does not loop, the definition is wrong
self always represents the receiversuper always represents the receiversuper changes the lookup:/