@implementation ClassA
-(void)classAMethod{
NSLog(@"AAAAAAAAA");
}
@end
@implementation ClassB
-(void)classBMethod{
NSLog(@"BBBBBBBBBB");
}
@end
@implementation ClassC
-(instancetype)init{
self = [super init];
if (self) {
_a = [[ClassA alloc]init];
_b = [[ClassB alloc]init];
}
return self;
}
-(void)classAMethod{
[_a classAMethod];
NSLog(@"子类");
}
-(void)classBMethod{
[_b classBMethod];
NSLog(@"子类");
}
ClassC *c = [[ClassC alloc] init];
[c classAMethod];
打印结果:
AAAAAA
子类