• 代码文件objective c 中继承的实现


    本文纯属个人见解,是对前面学习的总结,如有描述不正确的地方还请高手指正~

        

        Rectangle.h 文件代码:

        #import <Foundation/Foundation.h>

    @interface Rectangle : NSObject
    {
        int _width;
        int _height;
    }
    @property (nonatomic,assign) int width;
    @property (nonatomic,assign) int height;
    -(Rectangle *) initWithWidth:(int)w AndHeight:(int)h;
    -(void) print;
    @end

        Rectangle.m 文件代码:

        
    #import "Rectangle.h"

    @implementation Rectangle
    @synthesize width=_width;
    @synthesize height=_height;
    -(Rectangle *) initWithWidth:(int)w AndHeight:(int)h
    {
        self=[super init];
        if(self)
        {
        self.width=w;
        self.height=h;
        }
        return self;
    }
    -(void)print
    {
        NSLog(@"the height is %d ,the width is %d",self.height,self.width);
    }
    @end

        Square.h 文件代码:

        #import "Rectangle.h"

        @interface Square : Rectangle

        {

        int _d;

        }

        -(Square *)initSquareWith(int)w AndHeight:(int)h Andval:(int)d;

        @property (nonatomic,assign)int d;

        每日一道理
    灯,带有一种明亮的光,每当深夜来临,是它陪伴着你,如此默默无闻。它是平凡的,外表华丽与否,那都是一样的,珍珠点缀,水晶加饰的灯它只能用以装饰,来满足人们的虚荣心,比起这,普普通通的日光灯是幸运的,因为它照明的本性没有改变,如同生活中的一部分人平平凡凡却实实在在。

        @end

        Square.m 文件代码:

        #import "Square.h"

    @implementation Square
    @synthesize d=_d;
    -(Square*)initSquareWith(int)w AndHeight:(int)h Andval:(int)d
    {
        self=[super init];
        if(self)
        {
        self.height=h;
        self.width=w;
        self.d=d;
        }
        return self;
    }
    -(void)print //实现重载
    {
        NSLog(@"the d is %d,the width is %d,the height is %d",self.d,self.width,self.height);
    }
    @

        main数函:

        
    #import <Foundation/Foundation.h>
    #import "Access.h"
    #import "Rectangle.h"
    #import "Square.h"
    int main(int argc, const char * argv[])
    {

        @autoreleasepool {
            Rectangle *test=[[Rectangle alloc] init];
            [test initWithWidth:3 AndHeight:4];
            [test print];
            Square *squareObj=[[Square alloc] init];
            [squareObj initSquareWith3 AndHeight:4 Andval:5];
            [squareObj print];
        }
        return 0;
    }

    文章结束给大家分享下程序员的一些笑话语录: 一个程序员对自己的未来很迷茫,于是去问上帝。
    "万能的上帝呀,请你告诉我,我的未来会怎样?"
    上帝说"我的孩子,你去问Lippman,他现在领导的程序员的队伍可能是地球上最大的"
    于是他去问Lippman。
    Lippman说"程序员的未来就是驾驭程序员"
    这个程序员对这个未来不满意,于是他又去问上帝。
    "万能的上帝呀,请你告诉我,我的未来会怎样?"
    上帝说"我的孩子,你去问Gates,他现在所拥有的财产可能是地球上最多的"
    于是他去问Gates。
    Gates说"程序员的未来就是榨取程序员"
    这个程序员对这个未来不满意,于是他又去问上帝。
    "万能的上帝呀,请你告诉我,我的未来会怎样?"
    上帝说"我的孩子,你去问侯捷,他写的计算机书的读者可能是地球上最多的"
    于是他去问侯捷。
    侯捷说"程序员的未来就是诱惑程序员"
    这个程序员对这个未来不满意,于是他又去问上帝。
    "万能的上帝呀,请你告诉我,我的未来会怎样?"
    上帝摇摇头"唉,我的孩子,你还是别当程序员了")

  • 相关阅读:
    [OpenJudge90][序列DP+乱搞]滑雪
    [OpenJudge8786][暴力DP]方格取数
    [OpenJudge8782][划分DP]乘积最大
    [OpenJudge8471][划分DP]切割回文
    [OpenJudge8462][序列DP]大盗阿福
    【棋盘DP】【OpenJudge7614】最低通行费
    【OpenJudge8464】【序列DP】股票买卖
    bzoj1674: [Usaco2005]Part Acquisition 裸dijkstra
    bzoj3040 最短路+配对堆优化
    poj1330|bzoj3732|noip2013 货车运输 kruskal+倍增lca
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3061634.html
Copyright © 2020-2023  润新知