本帖最后由 程序猿-2014 于 2014-4-14 01:30 编辑
不太清楚你那个事怎么回事 但是我复制过来打印的值却是正确的啊//父类Person.h
#import <Foundation/Foundation.h>
@interface Person : NSObject
{
NSString *_name;
}
@property NSString * name;
@property int age;
- (id)initWithName: (NSString *)name andAge: (int)age;
@end
//Person.m中
//#import "Person.h"
@implementation Person
-(id)initWithName: (NSString *)name andAge: (int)age
{
if (self = [super init]) {
_name = name;
_age = age;
}
return self;
}
@end
//子类Student.h
//#import " Person.h "
@interface Student : Person
@property int no;
- (id)initWithName: (NSString *)name andAge: (int)age andNo: (int)no;
@end
//Student.m中
//#import "Student.h"
@implementation Student
- (id)initWithName: (NSString *)name andAge: (int)age andNo: (int)no
{
if (self = [super initWithName:name andAge: age]) {
_no = no;
}
return self;
}
@end
//主函数main.m中
//#import <Foundation/Foundation.h>
//#import " Person.h"
//#import "Student.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
Student *s = [[Student alloc] initWithName : @ " Jame " andAge: 29 andNo: 10];
NSLog(@"..................");
}
return 0;
}
===================================
|
|