私有變數和私有方法

2021-07-09 07:43:42 字數 700 閱讀 4717

//

// person.h

// oc語言學習

#import /*

例項變數(成員變數)既可以在@inte***ce中定義,

也可以在@implementation中定義

*/@inte***ce person : nsobject

//如果只有方法的實現,沒有方法的宣告,那麼該方法就是私有方法

//但是在oc中沒有真正的私有方法,因為oc是訊息機制

//- (void)test;

@end

//

// person.m

// oc語言學習

// oc語言學習

#import #import "person.h"

int main(int argc, const char * argv)

76,私有變數和私有方法

import inte ce person nsobject end implementationperson 下面是私有的成員變數 void setname nsstring name void setage int age nsstring name int age print 就是私有方法 v...

私有屬性和私有方法

應用場景及定義方式 應用場景 在實際開發中,物件的某些屬性或方法可能只希望在物件的內部使用,而不希望在外部被訪問到 私有屬性 就是 物件 不希望公開的 屬性 私有方法 就是 方法 不希望公開的 方法 定義方法 在定義屬性或方法時,在屬性名或者方法名前增加兩個下劃線,定義的就是私有屬性或方法 clas...

私有屬性和私有方法

應用場景 定義方式 不要問女生的年齡 self.age 18 def secret self print 我的年齡是 d self.age xiaofang women 小芳 私有屬性,外部不能直接訪問 print xiaofang.age 私有方法,外部不能直接呼叫 xiaofang.secret...