標籤:style blog color 使用 io for
//長方形的類的聲明與實現
#import <Foundation/Foundation.h>@interface Rect2 : NSObject{// float chang;// float w;}@property float chang;@property float w;- (float)sizeOfRect;@end#import "Rect2.h"@implementation Rect2//@synthesize chang;//@synthesize w;- (float)sizeOfRect{ NSLog(@"%@", self); return (self.chang)*(self.w);}@end//長方體的類的聲明與定義#import <Foundation/Foundation.h>#import "Rect2.h"@interface LiFangTi : Rect2{// float height;}@property float height;- (float)tiJiFor;@end#import "LiFangTi.h"@implementation LiFangTi-(float)tiJiFor{ return self.w*self.height*self.chang;}@end#import "ViewController.h"#import "LiFangTi.h"#import "Rect2.h"@interface ViewController () @end@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; Rect2 *rect=[[Rect2 alloc]init]; rect.chang=1; rect.w =2; NSLog(@"%@", rect); NSLog(@"%f",[rect sizeOfRect]); LiFangTi *liFangTi=[[LiFangTi alloc]init]; liFangTi.chang=1.0; liFangTi.w =3.0; liFangTi.height=3.0; NSLog(@"%f",[liFangTi tiJiFor]);}