#import "Person.h"
@interface Teacher : Person
@property(nonatomic,readonly,copy)NSString *subject; // 科目
-(void)setSubject:(NSString *)subject;
-(void)teaching;
@end
#import "Teacher.h"
@implementation Teacher
-(void)setSubject:(NSString *)subject
{
_subject = [subject copy];
}
-(void)teaching
{
NSLog(@"开始上课,我教 %@",_subject);
}
@end
Teacher *lily = [[Teacher alloc] initWithName:@"lily" age:32 gender:GenderWoman];
[lily setSubject:@"语文"];
[lily introduce]; // 自我介绍,我的名字是 : lily,年龄 : 32,性别 : 2
[lily teaching]; // 开始上课,我教 语文
网友评论