一直子类调父类有些问题
#import <Foundation/Foundation.h>
@interface Animal : NSObject
- (void)test1;
- (void)test2;
- (void)test3;
@end
@implementation Animal
- (void)test1
{
NSLog(@"Animal-test1");
}
- (void)test2
{
NSLog(@"Animal-test2");
}
@end
@interface Dog : Animal
@end
@implementation Dog
- (void)test1
{
NSLog(@"Dog-test1");
}
- (void)test3
{
NSLog(@"Dog-test3");
}
@end
int main()
{
Dog *dog = [Dog new];
[dog test1];//Dog-test1
[dog test2];//dog没有test2方法实现可以调用父类test2方法吗?
[dog test3];//Dog-test3
return 0;
}
|
|