Inheritance often is used to extend a class. As an example, let’s assume that you’ve just been assigned the task of developing some classes to work with 2D graphical objects such as rectangles, circles, and triangles. For now, we’ll worry about just rectangles. Let’s go back to exercise 7 from Chapter 4, “Data Types and Expressions,” and start with the
@interface section from that example:
@interface Rectangle: NSObject@property int width, height;-(int) area;-(int) perimeter;@end
You’ll have synthesized methods to set the rectangle’s width and height and to return those values, and your own methods to calculate its area and perimeter. Let’s add a method that will ...