下面就是自己今天下午学的视频自己乱写的代码,请各位大神勿喷啦
- //
- // main.m
- // 第一个类
- //
- // Created by apple on 14-5-20.
- // Copyright (c) 2014年 itcast. All rights reserved.
- //
- #import <Foundation/Foundation.h>
- @interface Dog : NSObject
- {
- char name;
- int age;
- }
- - (void)run;
- - (void)eat;
- @end
- @implementation Dog
- - (void)run
- {
- NSLog(@"dog is running");
- }
- - (void)eat
- {
- NSLog(@"dog is eating");
- }
- @end
- @interface Car : NSObject
- {
- @public
- int speed;
- int whlees;
- Dog *dog;
- }
- - (void)run;
- - (void)stop;
- - (void)liugou;
- - (void)eatdog;
- @end
- @implementation Car
- - (void)liugou
- {
- [dog run];
- }
- - (void)eatdog
- {
- [dog eat];
- }
- -(void)run
- {
- NSLog(@"车在跑了");
- }
- -(void)stop
- {
- NSLog(@"车停了");
- }
- @end
- int main(int argc, const char * argv[])
- {
- Car *c = [Car new];
- Dog *d = [Dog new];
- c->dog= d;
- [c liugou];
- [c run];
- [c stop];
- return 0;
- }
复制代码 |
|