#import
@interface Stuent : NSObject
{
int age;
NSString * name;
}
@property int age;
@property(nonatomic,retain) NSString * name;
//-(void)print;
@end
#import "Stuent.h"
@implementation Stuent
@synthesize age;
@synthesize name;
@end
#import "Stuent.h"
@interface Stuent (New)
-(void)info;
@end
#import "Stuent+New.h"
@implementation Stuent (New)
-(void)info
{
NSLog(@"%@,%d",name,age);;
}
@end
#import
#import "Stuent.h"
#import "Stuent+New.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
// insert code here...
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Stuent * student = [[Stuent alloc] init];
student.name = @"lilei";
student.age = 24;
//[student print];
NSLog(@"Hello, World!");
[student info];
[student release];
[pool drain];
}
return 0;
}
本文深入探讨了面向对象编程的基本概念,通过实例展示了如何在类中添加新方法,并使用属性进行操作。主要内容包括类的定义、属性的合成、方法的实现及调用,以及在实际应用中的操作演示。
1156

被折叠的 条评论
为什么被折叠?



