#import <Foundation/Foundation.h>
@interface Person : NSObject
- (void) test;
- (void) test:(int) ab;
+ (void) test;
@end
@implementation Person
- (void) test
{
NSLog(@"调用了对象方法test");
}
- (void) test:(int) a
{
NSLog(@"%d", a);
}
+ (void) test
{
NSLog(@"调用了类方法test");
}
@end
int main()
{
[Person test];
Person *p = [Person new];
[p test];
[p test:22];
return 0;
}
//-------------------------------------------------自己-----------------------------------
(1)由于OC本质上是C语言,可以想象一下在C语言中这样子的写法会不会报错:
@interface Person : NSObject
@end
@implementation Person
@end
int main() {
Person *p = [Person new];
[p test]; // 编译链接都不会报错,运行报错
return 0;
}
向person对象发送test消息
Unrecognized Selector Sent to Instance
总结:(1)OC中可以不进行声明,只有实现,但基本上不这样子做;
(2)OC在运行的时候检测方法是否实现;