A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© chain 中级黑马   /  2014-6-23 17:56  /  743 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 chain 于 2014-6-23 21:46 编辑

今天看了某本IOS开发有关的书籍,里面有这样一段话,self和super这两个关键字不能用在类方法中,试验如下:
  1. #import "Person.h"

  2. @implementation Person

  3. + (void)test1
  4. {
  5.     NSLog(@"人调用了test方法");
  6.     [self test2];
  7. }

  8. + (void)test2
  9. {
  10.     NSLog(@"人调用了test2方法");
  11. }

  12. @end
复制代码
  1. #import "Student.h"

  2. @implementation Student

  3. + (void)test1
  4. {
  5.     [super test1];
  6. }

  7. @end
复制代码
  1. #import <Foundation/Foundation.h>
  2. #import "Pesrson.h"
  3. #import "Student.h"


  4. int main(int argc, const char * argv[])
  5. {
  6.     [Person test1];
  7.    
  8.     [Student test1];

  9.     return 0;
  10. }
复制代码

程序运行结果: 2014-06-23 17:50:57.496 test[378:303] 人调用了test方法
2014-06-23 17:50:57.497 test[378:303] 人调用了test2方法
2014-06-23 17:50:57.497 test[378:303] 人调用了test方法
2014-06-23 17:50:57.498 test[378:303] 人调用了test2方法
Program ended with exit code: 0

大家一起来谈谈究竟书上为什么说self和super不能用在类方法中

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马