zoukankan      html  css  js  c++  java
  • 实现Square类,让其继承自Rectangle类,并在Square类增添新属性和方法

     1 #import <Foundation/Foundation.h>
     2 
     3 @interface Rectangle : NSObject{
     4     int width;
     5     int height;
     6 }
     7 @property int width,height;
     8 -(int) area;
     9 -(int) perimeter;
    10 -(void)setWidth:(int)w andHeight:(int)h;
    11 
    12 @end
    13 
    14 
    15 #import "Rectangle.h"
    16 
    17 @implementation Rectangle
    18 @synthesize width,height;
    19 -(void)setWidth:(int)w andHeight:(int) h{
    20     width=w;
    21     height=h;
    22 }
    23 -(int) area{
    24     return width*height;
    25 }
    26 -(int) perimeter{
    27     return (width+height)*2;
    28 }
    29 
    30 @end
    31 
    32 
    33 
    34 #import <Foundation/Foundation.h>
    35 #import "Rectangle.h"
    36 @interface Square : Rectangle
    37 -(void) setSide:(int) s;
    38 -(int)side;
    39 -(int)area;
    40 -(int)perimeter;
    41 
    42 @end
    43 
    44 
    45 #import "Square.h"
    46 
    47 @implementation Square
    48 
    49 -(void) setSide:(int) s{
    50     [self setWidth:s andHeight:s];
    51 }
    52 
    53 -(int) side{
    54     return width;
    55 }
    56 
    57 -(int)area{
    58     return width*width;
    59 }
    60 
    61 -(int)perimeter{
    62     return 2*(width+height);
    63 }
    64 @end
  • 相关阅读:
    Hadoop-MyEclipse安装配置
    grid搜索最优参数
    python数据集处理
    集合框架
    Java泛型集合
    python机器学习工具包
    IO流
    Eclipse导入Hadoop源码项目及编写Hadoop程序
    Hadoop日志以及日志的格式和命名组成
    VIM键盘映射 (Map)
  • 原文地址:https://www.cnblogs.com/wsq724439564/p/3272914.html
Copyright © 2011-2022 走看看