用继承实现XYPoint和Circle两个类

 #import <Foundation/Foundation.h>
@protocol show
@required
-(void)printOn;
@end @interface XYPoint : NSObject<show>{
int x;
int y;
}
@property (nonatomic,assign)int x,y;
-(id)setX:(int)_x andY:(int)_y; @end #import "XYPoint.h" @implementation XYPoint
@synthesize x,y; -(id)setX:(int)_x andY:(int)_y{
self.x=_x;
self.y=_y;
return self;
}
-(void)printOn{
NSLog(@"x = %d ,y = %d",x,y);
}
@end #import <Foundation/Foundation.h>
#import "XYPoint.h"
@interface Circle : XYPoint<show>{
int radius;
}
@property (nonatomic,assign)int radius;
-(id)initWithX:(int)_x andY:(int)_y andRadius:(int)_r;
-(double)area;
-(double)perimeter;
@end #import "Circle.h" @implementation Circle
@synthesize radius;
-(id)initWithX:(int)_x andY:(int)_y andRadius:(int)_r;
{
self.x=_x;
self.y=_y;
self.radius=_r;
return self;
} -(double)area{
return 3.14*radius*radius;
} -(double)perimeter{
return *,*radius;
} -(void)printOn{
NSLog(@"x = %d, y = %d ,radius = %d",x,y,radius); }
@end
上一篇:JSTL与EL(转)


下一篇:算法之插入排序(inertionSort)