// 设计一个方法,用来和其他车比较车速,返回车速的差距
#import <Foundation/Foundation.h>
@interface Car : NSObject
@property (nonatomic, assign) int speed;
- (int)compare:(Car *)newCar;
@end
@implementation Car
- (int)compare:(Car *)newCar{
return self.speed - newCar.speed;
}
@end
int main(int argc, const char * argv[]){
Car *c1 = [[Car alloc] init];
Car *c2 = [[Car alloc] init];
c1.speed = 200;
c2.speed = 150;
int res = [c1 compare:c2];
NSLog(@"res = %d", res);
return 0;
}
时间: 2024-10-06 08:45:56