从0开始学习OC程序-第9天

来源:互联网 发布:淘宝psn点卡 编辑:程序博客网 时间:2024/06/04 19:21
//继承的使用#import <Foundation/Foundation.h>@interface Animal : NSObject{    int _age;    double _weight;}-(void)setAge:(int)ageNumer;-(int) age;-(void)setWeight:(double)weightNumber;-(double)weight;@end@implementation Animal-(void)setAge:(int)ageNumer{    _age = ageNumer;}-(int) age{    return _age;}-(void)setWeight:(double)weightNumber{    _weight = weightNumber;}-(double)weight{    return _weight;}@end@interface Dog : Animal@end@implementation Dog@end@interface Cat : Animal@end@implementation Cat@endint main(){    Cat *cat = [Cat new];    [cat setAge:10];    NSLog(@"��的年龄是:%d",[cat age]);    Dog *dog = [Dog new];    [dog setAge:12];    NSLog(@"��的年龄是:%d",[cat age]);}
0 0
原创粉丝点击