A.OC弱语法
1.在运行的时候才会检查方法的声明和实现
2.没有声明只有实现的方法也能正常运行,只要在调用之前定义即可
3.类的声明必须存在,否则会出现运行时错误
B.类方法
1.是类名调用的方法
2.使用加号修饰的方法
3.类方法和对象方法可以重名
4.对象方法和类方法都允许多次声明,都不允许多次定义
5.类方法不能访问实例变量
1 #import <Foundation/Foundation.h>
2
3 @interface Person : NSObject
4 - (void) test;
5 - (void) test:(int) ab;
6 + (void) test;
7
8 @end
9
10
11 @implementation Person
12 - (void) test
13 {
14 NSLog(@"调用了对象方法test");
15 }
16
17 - (void) test:(int) a
18 {
19 NSLog(@"%d", a);
20 }
21
22 + (void) test
23 {
24 NSLog(@"调用了类方法test");
25 }
26
27 @end
28
29
30 int main()
31 {
32 [Person test];
33
34 Person *p = [Person new];
35 [p test];
36 [p test:22];
37 return 0;
38 }
