• OC2-重写


    //
    //  Dog.h
    //  OC2-重写
    //
    //  Created by qianfeng on 15/6/17.
    //  Copyright (c) 2015年 qianfeng. All rights reserved.
    //
    
    #import "Animal.h"
    
    @interface Dog : Animal
    {
        float _weight;
    }
    @property (assign,nonatomic)float weight;
    @end
    
    
    //
    //  Dog.m
    //  OC2-重写
    //
    //  Created by qianfeng on 15/6/17.
    //  Copyright (c) 2015年 qianfeng. All rights reserved.
    //
    
    #import "Dog.h"
    //重写父类的继承过来的方法,不需要再次声明
    @implementation Dog
    -(void)printAnimalInformation
    {
        NSLog(@"name=%@,age=%i,,weight=%.2f",_name,_age,_weight);
    }
    -(void)showAnimalFood
    {
        NSLog(@"%@_____",[self class]);
    }
    @end
    //
    //  Animal.h
    //  OC2-重写
    //
    //  Created by qianfeng on 15/6/17.
    //  Copyright (c) 2015年 qianfeng. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    @interface Animal : NSObject
    {
        NSString *_name;
        int _age;
        
    }
    @property (copy,nonatomic)NSString *name;
    @property(assign,nonatomic)int age;
    -(void)showAnimalFood;
    -(void)printAnimalInformation;
    @end
    
    
    //
    //  Animal.m
    //  OC2-重写
    //
    //  Created by qianfeng on 15/6/17.
    //  Copyright (c) 2015年 qianfeng. All rights reserved.
    //
    
    #import "Animal.h"
    
    @implementation Animal
    -(void)showAnimalFood
    {
        NSLog(@"%@_____",[self class]);
    }
    -(void)printAnimalInformation
    {
        NSLog(@"name=%@,age=%i",_name,_age);
    }
    @end
    //
    //  main.m
    //  OC2-重写
    //
    //  Created by qianfeng on 15/6/17.
    //  Copyright (c) 2015年 qianfeng. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    #import "Dog.h"
    #import "Animal.h"
    int main(int argc, const char * argv[]) {
        @autoreleasepool {
            
            Dog *xiaobai =[[Dog alloc] init];
            xiaobai.name=@"121";
            xiaobai.age=12;
            xiaobai.weight=12;
            
            [xiaobai printAnimalInformation];
            [xiaobai showAnimalFood];
            
            Animal *xiaohei =[[Animal alloc] init];
            xiaohei.name=@"xiaohei";
            xiaohei.age=11;
            [xiaohei printAnimalInformation];
            [xiaohei showAnimalFood];
    
        }
        return 0;
    }
  • 相关阅读:
    Linux平台不同解压缩命令的使用方法
    poj 1274 The Perfact Stall
    Experience Design for Sexable Forum
    JavaScript中的Array对象方法调用
    iOS9适配小结
    [Servlet&amp;JSP] HttpSession会话管理
    Android中的跨进程通信方法实例及特点分析(一):AIDL Service
    OpenCV——PS滤镜算法之Spherize 球面化(凸出效果)
    《Effective Modern C++》翻译--条款4:了解怎样查看推导出的类型
    Android开发系列之ListView
  • 原文地址:https://www.cnblogs.com/0515offer/p/4583066.html
Copyright © 2020-2023  润新知