看个例子
@interface Person : NSObject
@property (nonatomic,strong) NSString *name;
-(void)test;
+(void)run;
@end
@implementation Person
-(void)test{
NSLog(@"test");
}
+(void)run{
NSLog(@"run");
}
@end
--------------------------------------
@interface Student : Person
-(void)eat;
@end
@implementation Student
-(void)eat{
NSLog(@"eat");
}
@end
--------------------------------------
int main(int argc, const char * argv[]) {
Person *p = [[Person alloc]init];
[p setName:@"ABC"];
[Person run];
[p test];
Student *stu = [[Student alloc]init];
[stu eat];
return 0;
}
类的本质及其存储
当程序调用
Person *p = [[Person alloc]init];
[p setName:@"ABC"];
[p test];
调用对象方法顺序: p对象–>Person实例对象isa–>Person类对象的方法列表里找对应的方法
调用对象方法顺序
当程序调用
[Person run];
调用类方法顺序: Person–>Person类对象isa–>Person元类对象的方法列表里找对应的方法
调用类方法顺序
类继承体系