// // main.m // a+b // #import <Foundation/Foundation.h> #import "Calcultor.h" int main(int argc, const char * argv[]) { Calcultor * cal = [[Calcultor alloc]init]; [cal setA:10]; [cal setB:20]; int result = [cal add]; NSLog(@"%d",result); NSLog(@"%d",[cal sub:10 andb1:10]); return 0; }
// // Calcultor.h // a+b // #import <Foundation/Foundation.h> @interface Calcultor : NSObject { int _a; int _b; } /*set get */ @property int a; @property int b; -(int)add; -(int)sub:(int)a1 andb1:(int)b1; @end
// // Calcultor.m // a+b // #import "Calcultor.h" @implementation Calcultor -(id)init { self = [super init]; if(self != nil) { _a = 0; _b = 0; } return self; } -(int)add { return _a + _b; //NSLog(@"a+b"); } -(int)sub:(int)a1 andb1:(int)b1; { _a = a1; _b = b1; return _a + _b; } @end
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-16 13:24:27