@interface Car : NSObject
{
@public
int wheels;
int speed;
}
- (void)run;
@end
@ implementation Car
- (void)run
{
NSLog(@"车子跑起来了!");
}
@end
int main()
{
Car *p = [Car new];
Car *p2 = [Car new];
p2->wheels = 5;
p2->speed = 300;
[p2 run]
p->wheels = 4;
p->speed = 250;
[p run]
NSLog(@"车子有%d个轮子,时速为:%dkm/h", p->wheels,p->speed );
NSLog(@"车子有%d个轮子,时速为:%dkm/h", p2->wheels,p2->speed );
return 0;
} |
|