@interface Caculator : NSObject
{
int _num1;
int _num2;
float _result;
}
+(float)add:(int)num1 andNum2:(int)num2;
-(float)avg:(int)num1 andnum2:(int) num2 ;
@end
@implementation Caculator
+(float)add :(int)num1 andNum2:(int)num2
{
return num1+num2;
}
-(float)avg:(int)num1 andnum2:(int) num2
{
return [Caculator add :(int)num1 andNum2:(int)num2/2];
}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
//对象方法调用类方法
Caculator * haha = [Caculator new];
float av = [haha avg:3 andnum2:3];
NSLog(@"%.2f",av);
}
return 0;
}
|
|