黑马程序员技术交流社区
标题:
笔记10
[打印本页]
作者:
15132876050
时间:
2015-8-22 21:48
标题:
笔记10
1. #import <Foundation/Foundation.h> 2. #pragma mark 狗类的声明 3. typedef enum{white,blake} Color; 4. typedef enum{xiong,ci} Sex; 5. @interface Dog:NSObject 6. { 7. @public 8. Color _color; 9. Sex _sex; 10. float _speed; 11. } 12. -(void)eat:(NSString *)foodName; 13. -(void)run; 14. @end 15. #pragma mark 狗类的实现 16. @implementation Dog 17. -(void)eat:(NSString *)foodName{ 18. NSLog(@"狗在吃%@",foodName); 19. } 20. -(void)run{ 21. NSLog(@"%d,%d,%.2f",_color,_sex,_speed); 22. } 23. @end 24. #pragma mark 人类的声明 25. @interface Person:NSObject 26. { 27. @public 28. NSString *_name; 29. Dog *_dog; 30. } 31. -(void)wei:(NSString *)foodName; 32. -(void)liu; 33. @end 34. #pragma mark 人类的实现 35. @implementation Person 36. -(void)wei:(NSString *)foodName{ 37. [_dog eat:foodName]; 38. } 39. -(void)liu{ 40. [_dog run]; 41. } 42. @end 43. int main(int argc ,const char * argv[]){ 44. @autoreleasepool { 45. Dog *dog=[Dog new]; 46. dog->_color=white; 47. dog->_sex=ci; 48. dog->_speed=34.0f; 49. 50. Person *p=[Person new]; 51. p->_name=@"三多"; 52. p->_dog=dog; 53. 54. [p wei:@"馒头"]; 55. [p liu]; 56. 57. }
58. }
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2