- #import<Foundation/Foundation.h>
- #interface Car:NSObject{
- @int tire;//定义变量
- @NSString *brand;//定义一个字符串
- @NSString *color;
- }
- -(void)show;//声明函数
- +(void)run;
- @end
- @implementation Car//函数实现
- -(void)show(){//实例函数
- NSLog(@"%d,%@,%@",tire,brand,color);
- }
- +(void)run(){//类的函数
- NSLog(@"%d,%@,%@",tire,brand,color);
- }
- @end
- int main(int argc,const char*argv[]){
- @autoreleasepool{
- Car *car=[Car new];//类的实例化,产生对象
- car->tire=4;//对象名调用变量
- car->brand="Posche";
- car->color="black";
- [car show];//对象名调用函数
- [car run];}
-
- }
复制代码 |
|