无参方法方法声明实现及调用 #import <Foundation/Foundation.h>
@interface Car : NSObject //创建一个类 {//声明 @public; int wheel; NSString *color; int speed; } -(void)run; //定义了无参无返回值的方法 -(void)stop; @end
@implementation Car //方法的具体实现 -(void)run{ NSLog(@"车跑起来了!"); } -(void)stop{ NSLog(@"车停下了!"); } @end
int main(){ Car *car1=[Car new]; [car1 run]; [car1 stop]; }
|