zoukankan      html  css  js  c++  java
  • 面向对象的写码

    <?php

    /**
    *鸟能在空中飞;飞机也能在空中飞;超人也能在空中飞;
    *空警能管理和控制飞机的飞行线路,当然也能管理超人的飞行线路,但是对于鸟是无法管理的
    */

    abstract class DongWu{

    protected $mingZi;
    protected $diDian;

    public function __construct($mingZi, $diDian){
    $this->diDian = $diDian;
    $this->mingZi = $mingZi;
    }

    public function zhuoHaiChong(){
    echo $this->mingZi.$this->diDian.'捕捉害虫';
    }

    }
    interface Fly{
    public function fly();
    }
    class QingWa extends DongWu{
    // public function zhuoHaiChong(){
    // echo $this->mingZi.$this->diDian.'捕捉害虫';
    // }
    }
    class QingTing extends DongWu implements Fly {
    public function fly(){
    return $this->mingZi.'能飞,';
    }
    public function zhuoHaiChong(){
    echo $this->fly();
    parent::zhuoHaiChong();

    }
    }
    class ZhuoMuNiao extends DongWu implements Fly{
    public function fly(){
    return $this->mingZi.'能飞,';
    }
    public function zhuoHaiChong(){
    echo $this->fly();
    parent::zhuoHaiChong();
    }
    }

    $qw = new QingWa('青蛙', '在田间');
    $qw->zhuoHaiChong();
    echo '<br><br>';
    $qt = new QingTing('蜻蜓', '在空中');
    $qt->zhuoHaiChong();
    echo '<br><br>';
    $zmn = new QingTing('啄木鸟', '在树上');
    $zmn->zhuoHaiChong();

  • 相关阅读:
    生成器,生成器表达式。
    device busy
    memcached
    ps f
    Eviews9.0---软件安装
    免费提取百度文库 doc 文件
    Matlab---length函数
    Matlab 路径函数
    matlab中disp函数的简单用法
    MATLAB---dir函数
  • 原文地址:https://www.cnblogs.com/ZJCD/p/7206479.html
Copyright © 2011-2022 走看看