Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How declare methods in objective c? And how to call them?



How declare methods in objective c? And how to call them?..

Answer / Rohit Rai

In Objective-C, you can define methods (functions) inside classes. To declare a method, use the following syntax:

```objectivec
-(returnType)methodName:(parameters);
```

Here's an example of a method that calculates the area of a rectangle with two parameters for width and height:

```objectivec
- (double)calculateRectangleAreaWithWidth:(double)width andHeight:(double)height {
double area = width * height;
return area;
}
```

To call the method, create an instance of the class containing the method and invoke it:

```objectivec
Rectangle *rectangle = [[Rectangle alloc] init];
double result = [rectangle calculateRectangleAreaWithWidth:10.0 andHeight:5.0];
NSLog(@"The area is %f", result);
```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Objective-C Interview Questions

What is the function of the category?

1 Answers  


Can protocols have properties?

1 Answers  


How to convert objective c project to swift?

1 Answers  


Which class is used to establish a connection between applications to the web server?

1 Answers  


What is the difference between nsstring and string?

1 Answers  


What is an instancetype?

1 Answers  


What is difference between objective c and swift?

1 Answers  


What is method swizzling in objective c and why would you use it?

1 Answers  


What is the difference between a script and function?

1 Answers  


How to make a code snippet thread safe?

1 Answers  


How do I open .m files?

1 Answers  


How to reverse array in objective c?

1 Answers  


Categories