Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Iphone Objectivec Class level access

Related Tutorials


 
 

Share on Google+Share on Google+

Class level access

Advertisement
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.

 

 

 

MyClass.h


#import<Foundation/NSObject.h>
@interface MyClass:NSObject {
	
}
   -(void)instanceShow;
   +(void)classShow;
@end
MyClass.m


#import<stdio.h>
#import"MyClass.h"
@implementation MyClass
    -(void)instanceShow {
    printf("This is instance 
level method.\n");
}
    +(void)classShow {
    printf("This is class
 level method.");
}
@end
MyClassMain.m


#import<stdio.h>
#import"MyClass.m"
int main(){
MyClass *instance = [
  [MyClass alloc]init];
[instance instanceShow];
[MyClass classShow];
[instance release];
return ;
}
Output:


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.

 

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  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.

Posted on: March 22, 2005

Related Tutorials

Discuss: Class level access  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com