peren.h
#import <Foundation/Foundation.h>
@interface peren : NSObject
-(void)hello; //实例方法
+(void)hello2; //类方法
@end
peren.m
#import "peren.h"
@implementation peren
-(void)hello{
NSLog(@"-号");
[peren hello2]; //实例方法调用类方法
}
+(void)hello2{
NSLog(@"+号");
[[peren alloc] hello]; //类方法调用实例方法
}
@end
mian.m
</pre><p><pre name="code" class="objc">#import <Foundation/Foundation.h>
#import "peren.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
peren *h1=[[peren alloc]init];
[h1 hello]; //实例方法的调用
[peren hello2]; //类方法的调用
}
return 0;
}