Correcting teacher:查无此人
Correction status:qualified
Teacher's comments:完成的不错,继续加油。
abstract class a{
public $name;
public $age;
public function __construct($name,$age)
{
$this->name =$name;
$this->age = $age;
}
abstract protected function getInfo();
abstract protected function getInfo2($name);
public function getInfo3()
{
return '<hr>getInfo3:'.$this->name;
}
}
class b extends a {
public function getInfo(){
return '<hr>getinfo:'.$this->name .'---'.$this->age;
}
public function getInfo2($name)
{
$this->name = $name;
}
}
$b = new b('rambo','18');
echo $b->getInfo3();
echo $b->getInfo();
echo $b->getInfo2('ouyang');
echo $b->getInfo3();
interface v{
const country = '中国';
public function setFull($fuel);
public function setPurpose($purpose);
}
class Car implements v{
public $fuel;
public $purpose;
public function __construct($fuel='汽油',$purpose='家用')
{
$this->fuel = $fuel;
$this->purpose = $purpose;
}
public function setFull($fuel)
{
$this->fuel = $fuel;
}
public function setPurpose($purpose)
{
$this->purpose = $purpose;
}
public function getInfo(){
return $this->fuel . $this->purpose . '车';
}
}
$car = new Car();
echo $car -> getInfo();
echo '<hr>';
$car ->setFull('新能源');
$car ->setPurpose('出租');
echo $car -> getInfo();
abstract
定义抽象方法、抽象类{}
protected
时,子类不会自动继承, 必须手动重写构造方法,可以用parent::
手动调用interface
指定某个类必须实现的方法,但不需要定义方法的具体实现过程public
,且方法体必须是空的implements
类实现接口的关键字