Student.h
@interface Student : NSObject
@property(nonatomic) int age;
@property(nonatomic)NSString *name;
-(id)initWithAge:(int)Age;
-(id)initWithAgeAndName:(int)Age andName:(NSString*)Name;
@end
Student.m
#import "Student.h"
@implementation Student
@synthesize age;
@synthesize name;
-(id)initWithAge:(int)Age{
if(self=[super init])
{
age=Age;
}
return self;
}
-(id)initWithAgeAndName:(int)Age andName:(NSString *)Name{
if(self=[self initWithAge:Age])
{
name=Name;
}
return self;
}
@end
Main Function
#import <Foundation/Foundation.h>
#import "Student.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
Student* s=[[Student alloc] init];
s.age=10;
s.name=@"Student1";
NSLog(@"Student Name:%i,Age:%@",s.age,s.name);
Student* s1=[[Student alloc] initWithAge:10];
s1.name=@"ssssss";
NSLog(@"Student Name:%i,Age:%@",s1.age,s1.name);
Student* s2=[[Student alloc] initWithAgeAndName:10 andName:@"xxx"];
NSLog(@"Student Name:%i,Age:%@",s2.age,s2.name);
}
return 0;
}