------Java培训、Android培训、iOS培训、.Net培训、期待与您交流! -------
类对象的本质
/*
p 实例对象
Person 类对象
*/
#import <Foundation/Foundation.h>
@interface Person : NSObject
{
int _age;
}
- (void)palyGame;
+ (void)test;
@end
@implementation Person
- (void)playGame
{
NSLog(@"那个人正在撸啊撸");
}
+ (void)test
{
NSLog(@"+test");
}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
//1.使用类对象创建实例对象
Person *p = [Person new];
[p playGame];
//2. 使用代码的方式获取类对象,使用类名,c1就事一个类对象
Class c1 = [Person class];
NSLog(@"c1 = %@,%p",c1,c1);
//使用实例对象来获取类对象
Class c2 = [p class];
NSLog(@"c2 = %@,%p",c2,c2);
//用类对象调用类方法
[c2 test];
}
return 0;
}