Re: Super vs. self (newbie question)
Re: Super vs. self (newbie question)
- Subject: Re: Super vs. self (newbie question)
- From: Chris Hanson <email@hidden>
- Date: Sat, 10 Aug 2002 17:44:27 -0500
At 12:14 PM -0400 8/10/02, Jonas Roel wrote:
Can someone differentiate between self and super? Does self ONLY
refer to the method contained in the class, and super ONLY refers to
the class which contains such and such methods which is calling
super?
Not quite.
self refers to the object itself. So when you send a message to
self, the runtime starts by looking for an instance method in its
class, then if one's not found it looks for an instance method in its
superclass, then if one's not found it looks for an instance method
in the superclass of its superclass and so on.
super is just like self, except the runtime starts looking for
methods in the object's class's superclass instead of its class. It
then progresses to the superclass of the superclass and so on.
Of course in a class method, self and super refer to the class and
its superclass directly, and method resolution will look for class
methods rather than instance methods.
Hopefully this is a little clearer...
-- Chris
--
Chris Hanson | Email: email@hidden
bDistributed.com, Inc. | Phone: +1-847-372-3955
Making Business Distributed | Fax: +1-847-589-3738
http://bdistributed.com/ | Personal Email: email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.