1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| #import <Foundation/Foundation.h> #import "Person.h" #import "Student.h"
int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... Person *p=[[Person alloc]init]; //NSLog(@"Person 的名字是%@",p.name); //使用自定义name Person *p1=[[Person alloc] initWithName:@"Rose"]; //NSLog(@"Person的名字是%@",p1.name); Person *p2=[[Person alloc]initWithAge:10]; //NSLog(@"Person的年龄是%d",p2.age); Person *p3=[[Person alloc]initWithName:@"jack" andAge:10]; //NSLog(@"Person的名字是%@,年龄是%d",p3.name,p3.age); Student *stu=[[Student alloc]initWithNo:1]; //NSLog(@"Student的编号是%d",stu.no); Student *stu2=[[Student alloc]initWithName:@"jack" andAge:10 andNo:1]; NSLog(@"Student的名字是%@,年龄是%d,编号是%d",stu2.name,stu2.age,stu2.no); } return 0; }
|