Objective-C 继承
2013-09-30 09:14
351 查看
Location.h文件
#import <Foundation/Foundation.h>
@interface Location :NSObject
{
int m_nPointX;
int m_nPointY;
}
-(void)SetPointX:(int)nPointX;
-(void)SetPointY:(int)nPointY;
-(void)ShowXY;
@end
Location.m文件
#import "Location.h"
@implementation Location
-(void)SetPointX:(int)nPointX
{
m_nPointX = nPointX;
}
-(void)SetPointY:(int)nPointY
{
m_nPointY = nPointY;
}
-(void)ShowXY
{
NSLog(@"X = %d, Y = %d",m_nPointX,m_nPointY);
}
@end
/////////////////////////////////////////
Rectangle.h文件
#import "Location.h"
@interface Rectangle :Location
//继承Location
{
int m_nHigh;
int m_nWidth;
}
-(void)SetHigh:(int)nHigh;
-(void)SetWidth:(int)nWidth;
-(void)showHW;
@end
Rectangle.m文件
#import "Rectangle.h"
@implementation Rectangle
-(void)SetHigh:(int)nHigh
{
m_nHigh = nHigh;
}
-(void)SetWidth:(int)nWidth
{
m_nWidth = nWidth;
}
-(void)showHW
{
NSLog(@"H = %d,W = %d",m_nHigh,m_nWidth);
}
@end
#import "Rectangle.h"
int main(int argc,const
char * argv[])
{
@autoreleasepool {
// insert code here...
Rectangle *rect = [[Rectanglealloc]init];
[rectSetPointX:10];
[rectSetPointY:20];
[rectSetHigh:30];
[rectSetWidth:40];
[rectShowXY];
[rectshowHW];
}
return
0;
}
#import <Foundation/Foundation.h>
@interface Location :NSObject
{
int m_nPointX;
int m_nPointY;
}
-(void)SetPointX:(int)nPointX;
-(void)SetPointY:(int)nPointY;
-(void)ShowXY;
@end
Location.m文件
#import "Location.h"
@implementation Location
-(void)SetPointX:(int)nPointX
{
m_nPointX = nPointX;
}
-(void)SetPointY:(int)nPointY
{
m_nPointY = nPointY;
}
-(void)ShowXY
{
NSLog(@"X = %d, Y = %d",m_nPointX,m_nPointY);
}
@end
/////////////////////////////////////////
Rectangle.h文件
#import "Location.h"
@interface Rectangle :Location
//继承Location
{
int m_nHigh;
int m_nWidth;
}
-(void)SetHigh:(int)nHigh;
-(void)SetWidth:(int)nWidth;
-(void)showHW;
@end
Rectangle.m文件
#import "Rectangle.h"
@implementation Rectangle
-(void)SetHigh:(int)nHigh
{
m_nHigh = nHigh;
}
-(void)SetWidth:(int)nWidth
{
m_nWidth = nWidth;
}
-(void)showHW
{
NSLog(@"H = %d,W = %d",m_nHigh,m_nWidth);
}
@end
主函数
import <Foundation/Foundation.h>#import "Rectangle.h"
int main(int argc,const
char * argv[])
{
@autoreleasepool {
// insert code here...
Rectangle *rect = [[Rectanglealloc]init];
[rectSetPointX:10];
[rectSetPointY:20];
[rectSetHigh:30];
[rectSetWidth:40];
[rectShowXY];
[rectshowHW];
}
return
0;
}
相关文章推荐
- 【Objective-C】07-OC对象的继承
- 【初学】Objective-C学习笔记-看我72变之继承
- Objective-C 中如何变相实现多继承
- Objective-C基础教程2(继承和复合)
- Objective-C 学习笔记(二) 类继承,组合,多态等
- Objective-C基础(面向对象--下--三大特性--继承、多态)
- [8]姥爷幽默谈Objective-C-继承,多态,封装
- Objective-C - 继承的经典实例
- IOS之Objective-C 的“多继承”
- Objective-C中分类 (category)和扩展(Extension)以及继承(inherit)
- 5. 15 Objective-C 继承,方法,多态
- [Objective-C] 封装、继承和多态
- Objective-C 编程语言(4)协议---非继承关系上的相似性,正式的协议,非正式的协议
- objective-c和多继承
- Objective-C学习笔记--继承
- Objective-C语法之继承、封装、多态
- Objective - C基础: 第二天 - 8.继承的初体验
- Objective-C 学习笔记2 类与继承
- Objective-c - 继承的本质, new方法
- Objective-C,如何在不使用类继承的情况下,扩展已有类的实现