#import<Foundation/Foundation.h>
@interface Book :NSObject
{
int _price;
}
-(void)setPrice:(int)price
-(int)price;
@end
@implementation Book
-(void)setPrice:(int)price
{
_price = price;
}
-(int)price
{
return _price;
}
@end
//person类
@interface Person : NSObject
{
//组合
Book *_book;
}
-(void)setBook:(Book *)book;
-(Book *)book;
@end
@implementation
-(void)setBook:(Book *)book
{
_book = book
}
-(Book *)book
{
return book;
}
@end
int main()
{
//*******************
Book *b =[[Book alloc] init];//创建对象
Person *p1=[[Person alloc] init];
[p1 release];
//有alloc,马上写上[b release]在其下面
[b release];//回收对象
//********************
return 0;
} |
|