#import <Foundation/Foundation.h>
@interface FKBird : NSObject
- (void)fly ;
@end
FKBird类的创建和实现
#import "FKBird.h"
@implementation FKBird
- (void)fly {
NSLog(@"我在天空里自由自在地飞翔");
}
@end
#import <Foundation/Foundation.h>
#import "FKBird.h"
@interface FKOstrich : FKBird
@end
FKOstrich类的创建和实现
#import "FKOstrich.h"
@implementation FKOstrich
//重写父类方法时可以使用父类的方法名
- (void)fly {
NSLog(@"我只能在地上奔跑");
}
@end
main函数
int main(int argc, const char * argv[]) {
@autoreleasepool {
FKOstrich *os = [[FKOstrich alloc]init];
[os fly] ;
}
return 0;
}