Share on Google+Share on Google+

Class level access

Objective C have the class level feature.

Class level access


Objective-C provides facility of class level access. In the examples given above we have used '-' sign before method, '-' means instance level access. Now we will see how to define method that can be access on class level.





@interface MyClass:NSObject {

@implementation MyClass
    -(void)instanceShow {
    printf("This is instance 
level method.\n");
    +(void)classShow {
    printf("This is class
 level method.");

int main(){
MyClass *instance = [
  [MyClass alloc]init];
[instance instanceShow];
[MyClass classShow];
[instance release];
return ;

This is instance level method.
This is class level method.

Here in this example we have created a method named 'classShow' that can be accessed on class level means no need to create object to use classShow() method. We can directly use this method through class name. +(void)init method is called when objective-C program starts and it calls for every class so it is the better place to define class level variable.



Posted on: March 22, 2005 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Class level access  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image