编辑代码

#import <Foundation/Foundation.h>

//creat interface
@interface Car:NSObject
    -(void) run;
    -(void) didi;
    -(void) setColor:(NSString*) c;
    -(void) setPrice:(float) p;
    -(NSString*) getColor;
    -(float) getPrice;
@end

//creat implementation
@implementation Car
    
        NSString *color;
        float price;
    
    -(void) run{
        NSLog(@"my car is running!");
    }

    -(void) didi{
        NSLog(@"my car is comming,please get away");
    }

    -(void) setColor:(NSString*) c{
        color=c;
    }

    -(void) setPrice:(float) p{
        price=p;
    }

    -(NSString*) getColor{
        return color;
    }

    -(float) getPrice{
        return price;
    }
@end

int main(int argc, char* argv[]) {
    //there are two ways to instance a class(interface)
    //first way
    // Car *mycar = [Car new];
    //second way
    Car *mycar = [[Car alloc] init];
    
    [mycar setPrice:155550];
    [mycar setColor:@"red"];
    [mycar run];
    [mycar didi];
    NSLog(@"hello,%@ car!",[mycar getColor]);
    NSLog(@"%0.2f",[mycar getPrice]);
    return 0;
}