[Newbies] Question about inheritance
renggli at gmail.com
Fri Oct 13 14:22:41 UTC 2006
> Any points to clarify my confusion would be greatly appreciated.
This is an interesting question that is often asked at exams ;-)
The first thing to notice is that 'super' references the receiver but
changes the way the method it looked up, therefor
self = super
is always true. Furthermore
self class = super class
is true as well, since self and super both represent the receiver,
again super just changes the place where the lookup of #class is
started. "self class" and "super class" both answer the class of the
> It seems to me that "super new" and "superclass new" should do the same thing.
Now to come to your example: "super new" starts the lookup of #new in
the superclass, however the receiver of the message is unchanged and
you get an instance of the receiving class. "superclass new" creates
an instance of the superclass, as you would expect the receiver of the
message #new is the superclass.
More information about the Beginners