标签:方法 class 父类 div 属性 子类 etag 自定义 ace
@interface Person : NSObject @property int age; - (id)initWithAge:(int)age; @end @interface Student : Person @property NSString *name; - (id)initWithAge:(int)age andName:(NSString *)name; @end @implementation Student - (id)initWithAge:(int)age andName:(NSString *)name { if (self = [super init]) { // 这个_Age是父类中通过property自动在.m中生成的无法继承,不能直接访问 // _age = age; [self setAge:age]; _name = name; } return self; } @end
@interface Person : NSObject @property int age; - (id)initWithAge:(int)age; @end @interface Student : Person @property NSString *name; - (id)initWithAge:(int)age andName:(NSString *)name; @end @implementation Student - (id)initWithAge:(int)age andName:(NSString *)name { if (self = [super initWithAge:age]) { _name = name; } return self; } @end
(2)父类的属性交给父类的方法来处理,子类的方法处理子类自己独有的属性
自定义构造方法必须以intiWith开头,并且’W’必须大写
标签:方法 class 父类 div 属性 子类 etag 自定义 ace
原文地址:http://www.cnblogs.com/xufengyuan/p/6576342.html