가시성[접근자] Objc

@interface A : Object
{
//objc의 기본선언은 protected다.
    int z;    //protected
@public
    int a;    //public
@protected
    int b;    //protected
@private
    int c;    //private
    int d;    //private
}
@end

접근 테스트
#import <stdio.h>
#import <objc/Object.h>

@interface A : Object
{
@public
    int a;
@protected
    int b;
@private
    int c;
}
- (id)initWithA:(int)a int:(int)b int:(int)c;
- (void)WriteA;
@end

@interface B : A
- (void)WriteB;
@end

@implementation A
- (id)initWithA:(int)a int:(int)b int:(int)c {
    self->a = a;
    self->b = b;
    self->c = c;
    return self;
}
- (void)WriteA {
    printf("[A Write Method, a=%d, b=%d, c=%d]\n", a , b , c);
}
@end

@implementation B
- (void)WriteB {
    printf("[B Write Method, a=%d, b=%d]\n", a , b);
}
@end

int main() {
    B * objb = [[B new] initWithA:1000 int:100 int:10];
    printf("[main() scope, a=%d]\n" , objb->a);
    [objb WriteB];
    [objb WriteA];
    [objb free];
    return 0;
}

Share
이 글과 관련된 글
  1. [2009/11/20] 클래스 오브젝트 by 두목원숭이 (400)
  2. [2009/11/20] 클래스 메소드 by 두목원숭이 (466)
  3. [2009/11/20] 정적 클래스 by 두목원숭이 (412)
  4. [2009/11/20] 소멸자 [free] by 두목원숭이 (331)
  5. [2009/11/20] 생성자 [constructor] by 두목원숭이 (274)
Tag :

Leave Comments



T-NAVI