请看下面的程序,其中 TrafficTool是Bus的父类,判断执行main函数时,程序是否会报错,如果会报错,请指出错误。 TrafficTool.h #import
@interface TrafficTool : NSObject { @public int passenger; } - (void)carryPassenger; @end TrafficTool.m #import "TrafficTool.h" @implementation TrafficTool - (void)carryPassenger { NSLog(@"TrafficTool could carry %d passengers",passenger); } @end Bus.h #import "TrafficTool.h" @interface Bus : TrafficTool - (void)drainOil; - (void)carryPassenger; @end Bus.m #import "Bus.h" @implementation Bus - (void)carryPassenger { NSLog(@"Bus could carry %d passengers",passenger); } - (void)drainOil { NSLog(@"bus must drain oil"); } @end main.m #import
#import "TrafficTool.h" #import "Bus.h" int main(int argc, const char * argv[]) { TrafficTool *tt = [[Bus alloc]init]; [tt drainOil]; }