Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Access Modifiers and Garbage Collection  
 

Previously it was a requirement to allocate and release memory manually to assist with this problem it provides a reference-counting memory management system through retain and release keywords.

 

Access Modifiers and Garbage Collection

                         


Previously it was a requirement to allocate and release memory manually to assist with this problem it provides a reference-counting memory management system through retain and release keywords. But it is still required to take care of memory management by the programmer.
Going one step further in version 2.0 garbage collector is implemented as a conservative collector. This enable users to use full functionality of C as well as preserves Objective-C's ability to integrate with C++ code and libraries

Access Privileges

1.
Default access in objective-C is @protected.
2. Like C++ objective-C provide public and private access modifiers as well.
3.
@protected accessifier enable access elements in the subclass.

Example:
MyClass.h

#import<Foundation/NSObject.h>
@interface MyClass:NSObject {
	@private
    int a;
    int b;
}
   -(void) set:(int) x andb:(int) y;
   -(void) sum;
   -(void)show;
@end

MyClass.m

#import<stdio.h>
#import"MyClass.h"
@implementation MyClass
  -(void) set:(int) x andb:(int) y {
    a=x;
    b=y;
}
-(void) sum {
printf("Sum is : %d \n",a+b);
}
-(void)show{
printf("value of a is : %d \n",a);
printf("value of b is : %d \n",b);
}
@end

MyClassMain.m

#import<stdio.h>
#import"MyClass.m"
int main(){
MyClass *class1 = [[MyClass alloc] init];
MyClass *class2 = [[MyClass alloc] init];
[class1 set: 10 andb :12];
[class1 show];
[class1 sum];
// This is invalid statement because variable a is private.
// class2->a = 10;
class2->b = 15;
[class2 show];
[class2 sum];
[class1 release];
[class1 release];
return ;
}

Output:

value of a is : 10 
value of b is : 12 
Sum is : 22 
value of a is : 0 
value of b is : 15 
Sum is : 15 

                         

» View all related tutorials
Related Tags: c++ c class object diff io classes define if bit to creation sse bi e it li from in different

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.