- 新建一個 Student 類繼承于 Person 類
#import "Person.h"
extern NSString * const Education;
@interface Student : Person
@property(nonatomic,copy)NSString *homeTown; // 家鄉(xiāng)
@property(nonatomic,assign)NSUInteger classNum; // 班級
@property(nonatomic,copy)NSString *country; // 國籍
// 設(shè)置家鄉(xiāng) 班級 國籍
-(void)setHomeTown:(NSString *)homeTown andClassNum:(NSUInteger)classNum andCountry:(NSString *)country;
// 打印學(xué)生信息
-(void)introduce;
// 打印教育經(jīng)歷
-(void)printEduation:(NSString *)edcation;
// 打印職業(yè)規(guī)劃
-(void)printOccuptionPlan:(EmployeeType)employeeType;
@end
#import "Student.h"
NSString * const Education = @"本科";
@implementation Student
-(void)setHomeTown:(NSString *)homeTown andClassNum:(NSUInteger)classNum andCountry:(NSString *)country
{
_homeTown = [homeTown copy];
_classNum = classNum;
_country = [country copy];
}
-(void)introduce
{
NSLog(@"姓名: %@, 性別: %@, 年齡: %lu, 班級: %lu, 家鄉(xiāng): %@, 國籍: %@",
self.name,self.sex,(unsigned long)self.age,(unsigned long)self.classNum,self.homeTown,self.country);
}
-(void)printEduation:(NSString *)edcation
{
if (!edcation) {
NSLog(@"%@ 的學(xué)歷是: %@",self.name,Education);
} else {
NSLog(@"%@ 的學(xué)歷是: %@",self.name,edcation);
}
}
-(void)printOccuptionPlan:(EmployeeType)employeeType
{
switch (employeeType) {
case EmployeeTypeEngineer:
NSLog(@"%@ 想成為 工程師",self.name);
break;
case EmployeeTypeDesigner:
NSLog(@"%@ 想成為 設(shè)計師",self.name);
break;
case EmployeeTypeFinance:
NSLog(@"%@ 想成為 財務(wù)",self.name);
break;
default:
NSLog(@"%@ 還不清楚",self.name);
break;
}
}
@end
Student *lily = [[Student alloc] init]; // -[Person init]
lily.name = @"lily";
lily.age = 28;
lily.sex = @"女";
[lily setHomeTown:@"湖北" andClassNum:2 andCountry:Nationality];
[lily introduce]; // 姓名: lily, 性別: 女, 年齡: 28, 班級: 2, 家鄉(xiāng): 湖北, 國籍: 中國
[lily printEduation:NULL]; // lily 的學(xué)歷是: 本科
[lily printOccuptionPlan:EmployeeTypeFinance]; // lily 想成為 財務(wù)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。