//
// Student.h
// constructor_method
//
// Created by wu jianhua on 16-7-29.
// Copyright (c) 2016年 wujianhua. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface Student : NSObject
{
@public
int _age;
int _no;
@private
int _name;
}
- (void)setAge:(int)age;
- (void)setNo:(int)no;
- (int)age;
- (int)no;
//construct method
- (id)initWithAge:(int)age andNo:(int)no;
- (NSString *)description;
- (void) test;
+ (void) test2;
@end
//
// Student.m
// constructor_method
//
// Created by wu jianhua on 16-7-29.
// Copyright (c) 2016年 wujianhua. All rights reserved.
//
#import "Student.h"
@implementation Student
- (void)setAge:(int)age
{
_age=age;
}
-(int)age
{
return _age;
}
- (void)setNo:(int)no
{
_no=no;
}
- (int)no
{
return _no;
}
- (id)initWithAge:(int)age andNo:(int)no
{
self=[super init];//invoke super method
if (self !=nil)
{
//_age=age;
// _no=no;
self.age=age;
self.no=no;
}
return self;
}
- (NSString *)description
{
NSString *str= [NSString stringWithFormat:@"description age is %i and no is %i",_age,_no];
return str;
}
- (void)test
{
_age=1024;
}
+ (void)test2
{
//[self alloc];
//[Student alloc];
}
@end
//
// GoodStudent.h
// constructor_method
//
// Created by wu jianhua on 16-7-31.
// Copyright (c) 2016年 wujianhua. All rights reserved.
//
#import "Student.h"
@interface GoodStudent : Student
@end
//
// GoodStudent.m
// constructor_method
//
// Created by wu jianhua on 16-7-31.
// Copyright (c) 2016年 wujianhua. All rights reserved.
//
#import "GoodStudent.h"
@implementation GoodStudent
- (void)test
{
_age=10;
}
@end
//
// main.m
// constructor_method
//
// Created by wu jianhua on 16-7-29.
// Copyright (c) 2016年 wujianhua. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Student.h"
#import "GoodStudent.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
//Student *stu=[[Student alloc] init];
/*
id obj=[Student alloc];
Student *stu=[obj init];
[stu release];
*/
Student *stu=[[Student alloc] initWithAge:1024 andNo:12];
NSLog(@"age is %i and no is %i",stu.age,stu.no);
NSLog(@"%@",stu);
NSString *str=@"itcast";
NSLog(str);
GoodStudent* gs=[[GoodStudent alloc] init];
[gs test];
NSLog(@"age is %@",gs);
[stu release];
}
return 0;
}