Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
You can also overload methods. When you overload a method, you give it multiple definitions, and Objective-C chooses the correct version of the method based on the parameter list—the type and number of parameters must be different for each version of an overloaded method.
|
Code View:
Scroll
/
Show All #import <stdio.h>
#include <Foundation/Foundation.h>
@interface Class1: NSObject
-(void) print;
@end
@implementation Class1
-(void) print
{
printf("Hello there.\n");
}
@end
@interface Class2: Class1
-(void) print: (int) x;
@end
@implementation Class2
-(void) print: (int) x
{
printf("Your number is %i.\n", x);
}
@end
int main(void)
{
Class2 *c2 = [Class2 new];
[c2 print];
[c2 print: 5];
return 0;
}
.
.
.
|