Polymorphism: Same Name, Different Class
Program 9.1 shows the interface file for a class called Complex
, which is used to represent complex numbers in a program.
// Interface file for Complex class#import <Foundation/Foundation.h>@interface Complex: NSObject@property double real, imaginary;-(void) print;-(void) setReal: (double) a andImaginary: (double) b;-(Complex *) add: (Complex *) f;@end
You should have completed the implementation section for this class in exercises 5 and 6 from Chapter 7, “More on Classes.” We added an additional setReal:andImaginary:
method to enable you to set both the real and imaginary parts of your number with a single message and also synthesized ...
Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.