menu
more_vert
PHP面向对象练习

作者:dayu

2 刑警于今日7月17日凌晨抓捕了江苏常熟纵火案嫌疑犯

技术分享

3 青蛙一般在田间捕捉害虫;蜻蜓能飞,一般在空中捕捉害虫;啄木鸟也能飞,一般在树上捕捉害虫

/**
* 青蛙一般在田间捕捉害虫;蜻蜓能飞,一般在空中捕捉害虫;啄木鸟也能飞,一般在树上捕捉害虫;
*/
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();

PHP面向对象练习

原文地址:http://www.cnblogs.com/lxy1023-/p/7197335.html