Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 7. More on Classes > The self Keyword

The self Keyword

In Program 7.4, we decided to reduce the fraction outside of the add: method. We could have done it inside add: as well; the decision was completely arbitrary. However, how would we go about identifying the fraction to be reduced to our reduce method? We know how to identify instance variables inside a method directly by name, but we don’t know how to directly identify the receiver of the message.

You can use the keyword self to refer to the object that is the receiver of the current method. If inside your add: method you wrote


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial