设计一个“学生”的类 属性:年龄、姓名 行为:输出年龄和姓名;
#import <Foundation/Foundation.h>
@interface Student : NSObject{
int _age;
NSString *_name;
}
@property int age;
@property NSString* name;
-(void)print;
@end
#import "Student.h"
@implementation Student
-(void)print{
NSLog(@"name = %@,age = %d",_name,_age);
}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
Student *stu = [Student new];
stu.name = @"张三";
stu.age = 23;
[stu print];
}
return 0;
}
|
|