// // main.m // 有参 无参 // // Created by 赵云 on 15/7/8. // Copyright (c) 2015年 itcast. All rights reserved. //
#import <Foundation/Foundation.h>
//Caculate的声明 @interface Caculate:NSObject { @public; int _num1; //类的属性
int _num2;
} //无参无返回值 -(void)sum; //无参有返回值 -(int)sum1; //有参无返回值 -(void)sum:(int)a and:(int)b; //有参有返回值 -(int)sum1:(int)a and:(int)b; @end //Caculate的实现 @implementation Caculate
-(void)sum; { NSLog(@"%d",_num1+_num2); } -(int)sum1{ return _num1+_num2; } -(void)sum:(int)a and:(int)b{ NSLog(@"%d",a+b); } -(int)sum1:(int)a and:(int)b{ return a+b; }
@end
int main(int argc, const char * argv[]) { @autoreleasepool { //创建第一个对象 Caculate *cal=[Caculate new]; cal->_num1=10; cal->_num2=20; [cal sum]; int result=[cal sum1]; NSLog(@"%d",result); [cal sum:20 and:30]; int result2=[cal sum1:13 and:20]; NSLog(@"%d",result2);
} return 0; }
|