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