1、Student 继承 Person
- 下面打印结果是什么
@implementation Student
- (instancetype)init {
if (self = [super init]) {
NSLog(@"[self class] = %@",[self class]);
NSLog(@"[super class] = %@",[super class]);
NSLog(@"[self superclass] = %@",[self superclass]);
NSLog(@"[super superclass] = %@",[super superclass]);
}
return self;
}
@end
- [super message]
super的作用,告诉编译器,查找方法,从父类开始查找
消息的接受者,还是在哪里调用,就是谁
- [self superclass]
superclass的作用,获取父类
- (Class)class {
return object_getClass(self);
}
- (Class)superclass {
return class_getSuperclass(object_getClass(self));
}
打印结果:
[self class] = Student
[super class] = Student
[self superclass] = Person
[super superclass] = Person