现在的位置: 首页 > 综合 > 正文

OC语言— super用法

2017年10月05日 ⁄ 综合 ⁄ 共 584字 ⁄ 字号 评论关闭

/*
 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;
}

抱歉!评论已关闭.