首页 > 其他 > 详细

面向对象(游戏1)

时间:2017-07-23 14:17:41      阅读:286      评论:0      收藏:0      [点我收藏+]
<?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);

面向对象(游戏1)

原文:http://www.cnblogs.com/2833824328love/p/7224398.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!