//本人练习类的使用 #import <Foundation/Foundation.h> //创建一个枚举,描述车的颜色 typedef enum car{red,bule,black}che; @interface Car :NSObject { @public //全局变量 che _yanse; int _lunzi; float _haoyouliang;
} //实现 - (void)run; - (void)zairen; @end //行为 @implementation Car - (void)run{ NSLog(@"跑起来"); } - (void)zairen{ NSLog(@"只能载10个人"); } @end
int main(int argc, const char * argv[]) { @autoreleasepool { //创建对象 Car *p=[Car new]; //调用 p->_yanse=1; p->_lunzi=14; p->_haoyouliang=15.6f; [p run]; [p zairen]; NSLog(@"%d,%d,%.2f",p->_yanse,p->_lunzi,p->_haoyouliang);
|