• 实现Square类,让其继承自Rectangle类,并在Square类增添新属性和方法,在2的基础上,在Square类中重写Rectangle类中的初始化和打印方法


    实现Square类,让其继承自Rectangle类,并在Square类增添新属性和方法,在2的基础上,在Square类中重写Rectangle类中的初始化和打印方法

     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 -(void)print;
    12 
    13 @end
    14 
    15 
    16 #import <Foundation/Foundation.h>
    17 
    18 @interface Rectangle : NSObject{
    19     int width;
    20     int height;
    21 }
    22 @property int width,height;
    23 -(int) area;
    24 -(int) perimeter;
    25 -(void)setWidth:(int)w andHeight:(int)h;
    26 -(void)print;
    27 
    28 @end
    29 
    30 #import <Foundation/Foundation.h>
    31 #import "Rectangle.h"
    32 @interface Square : Rectangle
    33 
    34 -(void) setSide:(int) s;
    35 -(int)side;
    36 -(int)area;
    37 -(int)perimeter;
    38 -(void)print;
    39 
    40 @en
    41 
    42 #import "Square.h"
    43 
    44 @implementation Square
    45 
    46 -(void) setSide:(int) s{
    47     [self setWidth:s andHeight:s];
    48 }
    49 
    50 -(int) side{
    51     return width;
    52 }
    53 
    54 -(int)area{
    55     return width*width;
    56 }
    57 
    58 -(int)perimeter{
    59     return 2*(width+height);
    60 }
    61 
    62 -(void) print{
    63     NSLog(@"side  %d",width);
    64 }
    65 
    66 @end
  • 相关阅读:
    [PHP] laravel框架注意bootstrap/cache
    [git] git拉取远程分支代码
    Prometheus监控系统(4)pushgateway及自定义脚本
    k8s 学习
    pxc /Galera Cluster详解
    Percona Monitoring and Management
    etcd获取所有key
    kubernetes Pod驱逐迁移drain用法
    kubernetes etcd数据管理
    办公环境下k8s网络互通方案
  • 原文地址:https://www.cnblogs.com/wsq724439564/p/3272916.html
Copyright © 2020-2023  润新知