Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

Class level access

Objective C have the class level feature.

Ads

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.

 

Advertisements

Ads
Share on Google+Share on Google+

Class level access

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

Advertisements

 

Discuss: Class level access  

Post your Comment


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

Ads

 

Ads