Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:抽象类就是一个未发育成熟的接口, 部分实现的接口的功能
<?php
//抽象类
abstract class a{
public $name;
public function __construct($name){
$this->name=$name;
}
public function af(){
echo $this->name;
}
//抽象方法不能有内容
abstract function aff();
}
class b extends a{
//b继承a后,必须把a里面的抽象方法实现
public function aff(){
echo $this->name;
}
}
$a =new b('张三');
$a->af();
<?php
//接口
interface ivehicle{
const CUNTRY='中国';
public function setFuel($fuel);
public function setPurpose($purpose);
}
//接口不可以有普通方法,不可以有成员变量
class car implements ivehicle{
public $fuel;
public $purpose;
public function __construct($fuel='汽油',$purpose='家用'){
$this->fuel=$fuel;
$this->purpose=$purpose;
}
public function setFuel($fuel){
$this->fuel=$fuel;
}
public function setPurpose($purpose){
$this->purpose=$purpose;
}
public function getInfo(){
return $this->fuel . $this->purpose . '车<br>';
}
}
$car=new Car();
echo $car->getInfo();
$car->setFuel('新能源');
$car->setPurpose('公交');
echo $car->getInfo();