A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© YuePr 中级黑马   /  2015-12-7 21:23  /  647 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. #import <Foundation/Foundation.h>
  2. @interface Dog : NSObject
  3. {
  4.     char *_name;
  5. }
  6. -(void)run;
  7. -(void)catchThief;
  8. @end
  9. @implementation Dog
  10. -(void)run
  11. {
  12.     NSLog(@"%s在跑",_name);
  13. }
  14. -(void)catchThief
  15. {
  16.     NSLog(@"警犬抓小偷");
  17. }
  18. @end

  19. @interface Police : NSObject
  20. {
  21.     Dog *_dog;
  22.     char *_name;
  23. }
  24. -(void)run;
  25. +(void)catchThief;
  26. -(void)setDog:(Dog *)dog;
  27. -(Dog *)getDog;
  28. @end
  29. @implementation Police
  30. -(void)run
  31. {
  32.     NSLog(@"%s在跑",_name);
  33. }
  34. +(void)catchThief
  35. {
  36.     NSLog(@"警察抓小偷");
  37. }
  38. -(void)setDog:(Dog *)dog
  39. {
  40.     _dog = dog;
  41. }
  42. -(Dog *)getDog
  43. {
  44.     return _dog;
  45. }
  46. @end

  47. int main()
  48. {
  49.     Police *jinPing = [Police new];
  50.     Dog *dog = [Dog new];
  51.     [jinPing setDog:dog];
  52.     [[jinPing getDog] catchThief];
  53.     return 0;
  54. }
复制代码

评分

参与人数 1黑马币 +2 收起 理由
iamcominghm + 2 赞一个!

查看全部评分

2 个回复

倒序浏览
写的不错啊
回复 使用道具 举报
不明所以
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马