OC类的继承-继承的特点

Object-C技术学习,更多资源请访问 https://www.itkc8.com

//  main.m

//  类的继承

//

//  Created by Goddog on 15/1/7.

//  Copyright (c) 2015年 Goddog. All rights reserved.

//

/*

 1.继承实现软件的复用性,每个子类只有一个直接的父类。

 2.实现继承的类称为子类,被继承的类称为父类(超类、基类)

 3.OC继承父类的语法:@interface SubClass : SuperClass

 */

 

//
//  NiceGirl.h
//  类的继承
//
//  Created by Goddog on 15/1/7.
//  Copyright (c) 2015年 Goddog. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Girl.h"

@interface NiceGirl : Girl

@end

 

//
//  NiceGirl.m
//  类的继承
//
//  Created by Goddog on 15/1/7.
//  Copyright (c) 2015年 Goddog. All rights reserved.
//

#import "NiceGirl.h"

@implementation NiceGirl

@end

 

//
//  Girl.h
//  类的继承
//
//  Created by Goddog on 15/1/7.
//  Copyright (c) 2015年 Goddog. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Girl : NSObject
@property (nonatomic,assign) int size;
-(void) doSome;
@end

 

//
//  Girl.m
//  类的继承
//
//  Created by Goddog on 15/1/7.
//  Copyright (c) 2015年 Goddog. All rights reserved.
//

#import "Girl.h"

@implementation Girl
@synthesize size = _size;
-(void) doSome
{
    NSLog(@"美女,尺寸:%i",_size);
}
@end

 

#import <Foundation/Foundation.h>
#import "NiceGirl.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        //创建对象
        NiceGirl* niceGirl = [[NiceGirl alloc] init];
        
        //访问父类的属性
        niceGirl.size = 34;
        //调用方法
        NSLog(@"调用方法%d",[niceGirl size]);
    }
    return 0;
}

 

Object-C技术学习,更多资源请访问 https://www.itkc8.com

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值