#import <Foundation/Foundation.h>
@interface Car: NSObject {
int _wheels; int _speed;
} - (void)run; - (void)carBeep; - (void)setWheels: (int)wheels; - (int)wheels; @property int _speed;
@end
@implementation Car
- (void)setWheels: (int)wheels { _wheels = wheels; } - (int)wheels { return _wheels; } - (void)run { NSLog(@"车子跑起来了"); }
- (void)carBeep { NSLog(@"car 响了"); } @end
@interface Aodi : Car - (void)carBeep; @end @implementation Aodi - (void)carBeep { NSLog(@"aodi 响了"); } @end
@interface Baoma : Car - (void)carBeep; @end @implementation Baoma - (void)carBeep { NSLog(@"baoma 响了"); } @end void leep(Car *c) { [c carBeep]; }
int main() { @autoreleasepool { Baoma *baoma = [Baoma new]; leep(baoma); Aodi *aodi = [Aodi new]; leep(aodi); //Car *car = [Car new]; baoma.wheels = 5; baoma._speed = 120;
int wnm = baoma.wheels; NSLog(@"baoma 有%d个轮子",wnm); //NSLog(@"%d个轮子的车子的速度是%d",car1->wheels,car1->speed); }
return 0; }
|