oc_study04
来源:互联网 发布:山东软件协会 编辑:程序博客网 时间:2024/06/05 01:04
多重类的方法嵌套
typedef enum { SexMan, SexWoman} Sex;typedef struct { int year; int month; int day;} Date;typedef enum { ColorBlack, ColorRed, ColorGreen} Color;#import <Foundation/Foundation.h>@interface Dog : NSObject{@public double weight; Color curColor;}- (void)eat;- (void)run;@end@implementation Dog- (void)eat{ weight = weight + 1; NSLog(@"狗狗吃完这餐后体重为%0.2lfKg", weight);}- (void)run{ weight = weight - 1; NSLog(@"狗狗跑完步后体重为%0.2lfKg", weight);}@end@interface Student : NSObject{ @public Sex sex; Date birthday; double weight; Color favColor; char * name; Dog * dog;}- (void)eat;- (void)run;- (void)print;- (void)walkDog;- (void)feedDog;@end@implementation Student- (void)eat{ weight = weight + 1; NSLog(@"学生吃完这餐后体重为%0.2lfKg", weight);}- (void)run{ weight = weight - 1; NSLog(@"学生跑完步后体重为%0.2lfKg", weight);}- (void)print{ NSLog(@"性别 = %d, 喜欢的颜色 = %d, 姓名 = %s, 生日 = %d-%d-%d", sex, favColor, name, birthday.year, birthday.month, birthday.day);}- (void)feedDog{ [dog eat];}- (void)walkDog{ dog->weight = dog->weight - 1; NSLog(@"学生遛完狗后狗的体重为%0.2lfKg", dog->weight);}@endint main(void){ Student * p = [Student new]; p->weight = 55.6789; Date Birth = {1992,2,10}; p->birthday = Birth; p->sex = SexMan; p->favColor = ColorBlack; p->name = "Jack"; [p eat]; [p run]; [p print]; p->dog = [Dog new]; p->dog->weight = 20; [p->dog eat]; [p->dog run]; [p walkDog]; [p feedDog]; return 0;}
0 0
- oc_study04
- 指针函数与函数指针的区别
- JQuery中$.ajax()方法参数详解
- 关于读书
- Eclipse工具使用技巧总结
- spring mvc @Responsebody支持问题
- oc_study04
- mybatis操作数据库是如果mapper文件中的id和java代码中的参数名字不同是报的错
- 以表格的方式返回MySql数据库中表的数据方法
- 1086. Tree Traversals Again
- 平凡的世界
- NYOJ 478 月老的烦恼(1)【因字数&&HDU 1215 七夕节】
- Divide Two Integers
- min sum
- [LeetCode][172][Factorial Trailing Zeroes]