- #import <Foundation/Foundation.h>
- @interface Person : NSObject
- {
- int _age;
- }
- - (void)test1;
- - (void)test2;
- + (void)test2;
- + (void)test3;
- + (void)test4;
- - (void)test4;
- @end
- @implementation Person
- - (void)test1
- {
- _age = 20;
-
- int _age = 10;
- NSLog(@"调用了-test1方法-%d", _age);
- [self test2];
- }
- - (void)test2
- {
- int _age = 10;
- NSLog(@"调用了-test2方法-%d", self->_age);
- }
- + (void)test2
- {
- int _age = 20;
- NSLog(@"调用了+test2方法-%d", _age);
- }
- + (void)test3
- {
- NSLog(@"调用了+test3方法");
- [self test4];
- }
- + (void)test4
- {
- NSLog(@"调用了+test4方法");
- }
- - (void)test4
- {
- NSLog(@"调用了-test4方法");
- }
- @end
- int main()
- {
- [Person test3];
-
- Person *p = [Person new];
- [p test1];
- return 0;
- }
- //运行后
- 2013-08-06 21:59:43.956 testOc[11962:303] 调用了+test3方法
- 2013-08-06 21:59:43.957 testOc[11962:303] 调用了+test4方法
- 2013-08-06 21:59:43.958 testOc[11962:303] 调用了-test1方法-10
- 2013-08-06 21:59:43.959 testOc[11962:303] 调用了-test2方法-20
复制代码 |