权限控制OC

2015-03-09  本文已影响97人  json_jie

1、@protected     本类 或者 子类 内部 使用

2、@public          本类 或者 子类 或者 任何地方使用

3、@private       本类内部使用

#pargma  父类

#import@interface FatherClass : NSObject

{

@protected    NSString *firstName;

@public    NSString *money;

@private  NSString *sex;

}

@end

#import "FatherClass.h"

@implementation FatherClass

-(id)init{

self = [super init];

if (self) {

firstName =  @"jie";

money = @"100万";

sex = @"男";

}

return self;

}

@end

#pargma  --- 子类

#import "FatherClass.h"

@interface SunClass : FatherClass

@end

#import "SunClass.h"

@implementation SunClass

-(id)init{

self = [super init];

if (self) {

[self nsolg];

}return self;

}

-(void)nsolg

{

firstName = @"sunJie";

money = @"sunMoney";

//    sex = @"sunNan";  私有的。不可以子类访问

}

@end

#pargma mark ----- 

#import "ViewController.h"

#import "SunClass.h"

#import "FatherClass.h"

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

FatherClass *father = [[FatherClass alloc] init];

father -> money = @"10万";

/**

*  类的外部  私有的 和 受保护的不可以访问(在外部的类)

*/

//    father -> sex = @"男";

//    father -> firstName = @"zhao";

SunClass *sun = [[SunClass alloc] init];

sun -> money = @"100万";

/**

*  类的外部  私有的 和 受保护的不可以访问(在外部的类)

*/

//    sun -> sex  = "man";

//    sun -> firstName = @"jie";

}

@end

上一篇 下一篇

猜你喜欢

热点阅读