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 6. Object-Oriented Programming > Verifying That an Object Belongs to a ...

Verifying That an Object Belongs to a Class

You can determine whether an object is a member of a certain class with the isMemberOfClass method. You’ll put that method to use in the next task to verify that a certain object is a member of a certain class, here called Class1. You can get the class’s name simply by sending it the message class like this: [Class1 class].

To use isMemberOfClass:

1.
Create a new program named isMemberOfClass.m.

2.
In isMemberOfClass.m, enter the code shown in Listing 6.13.

This code creates the Class1 class.

3.
Add the code to create an object of the Class1 class and verify that the object really is a member of the Class1 class (Listing 6.14).

4.
Save isMemberOfClass.m.

5.
Run the isMemberOfClass.m program.

You should see the following:

c1 is a member of Class1.


  

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