// // Car.h // 屬性 // // Created by 藍鷗 on 16/7/29. // Copyright © 2016年 luanbin. All rights reserved. // #import @interface Car : NSObject { // NSString *_brand; // float _price; } //屬性聲明 @property NSString *brand; @property float price; //屬性到底做了什麼??? /* 1,自動生成以_開頭的實例變量 2,自動生成set get的聲明 3,自動生成set get的實現 */ //set get //-(void)setBrand:(NSString *)brand; //-(NSString *)brand; //-(void)setPrice:(float)price; //-(float)price; //自定義初始化方法 -(id)initWithBrand:(NSString *)brand price:(float)price; -(void)run; -(void)stop; @end // // Car.m // 屬性 // // Created by 藍鷗 on 16/7/29. // Copyright © 2016年 luanbin. All rights reserved. // #import "Car.h" @implementation Car //@synthesize brand = _brand; //@synthesize price = _price; //-(void)setBrand:(NSString *)brand //{ // _brand = brand; //} //-(NSString *)brand //{ // return _brand; //} // //-(void)setPrice:(float)price //{ // _price = price; //} //-(float)price //{ // return _price; //} -(id)initWithBrand:(NSString *)brand price:(float)price { self = [super init]; if (self) { _brand = brand; _price = price; } return self; } -(void)run { NSLog(@"車正在疾馳"); } -(void)stop { NSLog(@"停車"); } @end