#import <Foundation/Foundation.h>
@interface Person : NSObject
{
NSString *_name;
}
-(void)setName:(NSString *)name;
-(NSString *)getName;
-(void)run;
@end
@implementation Person
-(void)setName:(NSString *)name{
_name = name;
}
-(NSString *)getName{
return _name;
}
-(void)run{
NSLog(@"%@跑路...",_name);
}
@end
@interface Police : Person
{
NSString *_gun;
}
-(void)catchThief;
@end
@implementation Police
-(void)catchThief{
NSLog(@"%@大喊:站住,别跑...",_name);
}
-(void)run{
NSLog(@"%@狂追...",_name);
}
@end
@interface Thief :Person
{
NSString *_knife;
}
-(void)stealThings;
@end
@implementation Thief
-(void)stealThings{
NSLog(@"%@正在偷东西...",_name);
}
@end
int main(){
Police *p = [Police new];
[p setName:@"成龙"];
Thief *t = [Thief new];
[t setName:@"吴彦祖"];
[t stealThings];
[p catchThief];
[t run];
[p run];
} |
|