码迷,mamicode.com
首页 > 其他好文 > 详细

类的使用与继承

时间:2014-07-24 10:04:16      阅读:221      评论:0      收藏:0      [点我收藏+]

标签: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]); }

类的使用与继承,布布扣,bubuko.com

类的使用与继承

标签:style   blog   color   使用   io   for   

原文地址:http://www.cnblogs.com/lidongq/p/3864656.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!