黑马程序员技术交流社区

标题: 继承的特点和大家分享一下子 [打印本页]

作者: hei军    时间: 2015-12-3 00:19
标题: 继承的特点和大家分享一下子
#import <Foundation/Foundation.h>
//父类
@interface Person : NSObject{
    char *_name;//姓名
    double _high;//身高
    double _weight;//体重
}
-(void)run;
-(void)setName:(char *)name;

@end

@implementation Person

-(void)run{
   
    NSLog(@"%s 跑....",_name);
}

-(void)setName:(char *)name{
    _name=name;
}

@end

//警察
@interface Police : Person{
   
    char *_qiang;
}
+(void)catchThief;
@end

@implementation Police


+(void)catchThief{
    NSLog(@"抓小偷...");
}

@end


//小偷
@interface Thief : Person{
    char *_dao;
}
+(void)tou;
@end

@implementation Thief

+(void)tou{
     NSLog(@"偷东西...");
}

@end

int main(){
    //小偷偷东西, 警察跑去抓小偷,小偷跑路
   Thief *t= [Thief new];
    [t setName:"thief"];
    Police *p=[Police new];
    [p setName:"police"];
   
    [Thief tou];
    [p run];
    [Police catchThief];
    [t run];
   
   
   
   
    return 0;
}




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2