1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| #include <Foundation/Foundation.h> typedef enum { SexMan, SexWomen }Sex; @interface Student : NSObject { int _no; Sex _sex; } -(void)setNo:(int)no; -(int)no; -(void)setSex:(Sex)sex; -(Sex)sex;
@end @implementation Student
-(void)setNo:(int)no { _no=no; } -(int)no { return _no; } -(void)setSex:(Sex)sex { _sex=sex; } -(Sex)sex { return _sex; } @end
int main() { Student *stu=[Student new]; [stu setSex:SexMan]; [stu setNo:10]; NSLog(@"学生的性别是%d,编号是%d",[stu sex],[stu no]); return 0; }
|