首先来看一段代码
代码语言:javascript复制#import <Foundation/Foundation.h>
@interface Person : NSObject
(void)pringName:(NSString *)name;
@end
代码语言:javascript复制#import "Person.h"
@interface Person()
@end
@implementation Person
(void)pringName:(NSString *)name
{
NSLog(@"Person-%@",name);
}
@end
代码语言:javascript复制#import <Foundation/Foundation.h>
#import "Person.h"
@interface Student : Person
@end
代码语言:javascript复制#import "Student.h"
@implementation Student
(void)pringName:(NSString *)name
{
NSLog(@"Student-%@",name);
}
@end
代码语言:javascript复制- (void)viewDidLoad {
[Student pringName:@"小明"];
}
代码语言:javascript复制2018-03-13 09:18:06.371043 0800 DD[50663:8176634] Student-小明
从上面的打印信息可以看到静态方法是可以被重写的