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