<?php/** * Created by PhpStorm. * User: Administrator * Date: 2017/7/18 * Time: 14:33 */interface IFlyyy{ public function fly(); }abstract class FeiObject implements IFlyyy{ protected $name; public function __construct($name){ $this->name = $name; } public function getName(){ return $this->name; } public function fly(){ echo $this->name.‘可以飞,‘; }}class Niao extends FeiObject{}class FeiJi extends FeiObject{}class ChaoRen extends FeiObject{}class KongJing extends FeiObject{ public function guanLi($fei){ if($fei instanceof Niao){ echo $this->name.‘无法管理‘.$fei->getName().‘的飞行线路‘; }else{ echo $this->name.‘可以管理‘.$fei->getName().‘的飞行线路‘; } }} $niao = new Niao(‘鸟‘);$niao->fly();$fj = new FeiJi(‘飞机‘);$fj->fly();$kj = new KongJing(‘空警‘);$kj->guanLi($niao);
时间: 2024-11-26 01:10:02