您的位置:首页 > 编程语言 > C语言/C++

OC语言— super用法

2014-07-24 23:07 176 查看
/*

super

1、直接调用父类中的某个方法

2、super处在对象方法中,那么就会调用父类的对象方法

super处在类方法中,那么就会调用父类的类方法

3、使用场合:子类重写父类的方法时想保留父类的一些行为

*/

#include <Foundation/Foundation.h>

@interface Zoombie : NSObeject

- (void)walk;

+ (void)test;

- (void)test;

@end

@implementation Zoombie

- (void)walk

{

NSLog(@"往前跳下");

}

+ (void)test

{

NSLog(@"Zoombie+test");

}

- (void)test

{

NSLog(@"Zoombie-test");

}

@end

@interface JumpZoombie: Zoombie

+ (void)haha;

@end

@implementation JumpZoombie

+ (void)haha

{

[super test];

}

- (void)walk

{

NSLog(@"往前跳2下");

//直接调用父类的walk方法

[super walk];

//NSLog(@"往前跳下");

}

@end

int main()

{

[JumpZoombie haha];

// JumpZoombie *jz=[JumpZoombie new];

// [jz walk];

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: