Objective-C program with multiple parameter


Objective-C enables programmer to use method with multiple parameter. These parameter can be of same type or of different type.
This is a sample program that shows sum of three numbers as output.

MyClass.h

#import<Foundation/NSObject.h>
@interface MyClass:NSObject{
}

// declare method for more than one parameter
-(int) sum: (int) a andb: (int) b andc:(int)c;
@end

MyClass.m

#import<stdio.h>
#import"MyClass.h"

@implementation MyClass
-(int) sum: (int) a andb: (int) b andc:(int)c;{
return a+b+c;
}
@end


MyClass.m

#import<stdio.h>
#import"MyClass.m"
int main(){
MyClass *class = [[MyClass alloc]init];

printf("Sum is : %d",[class sum : 5 andb : 6 andc:10]);
[class release];
return ;
}


Output:

Sum is : 21

Copy from http://www.roseindia.net/iphone/objectivec/objective-program-with-multiple-parameter.shtml

Advertisements
By dbglory Posted in IOS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s