#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 test2];
[dog test3];
return 0;
}
输出为:
Dog-test1
Animal-test2
Dog-test3
//先从子类中寻找有没有该方法,没有就向父类寻找
|
|