总结:接口是特殊的抽象类。
关键词:
父类:
interface Car
{
public function setFuel($fuel);
}
子类继承
class car implement Car
{
public function setFuel($fuel)
{ ....}
}
实例
<?php namespace _1009; //类是对象的模板,对象是类的实例化 interface iVehicle { public function setFuel($fuel); public function setPurpose($purpose); } class Car implements iVehicle { public $fuel; public $purpose; public function setFuel($fuel) { $this->fuel = $fuel; } public function setPurpose($purpose) { $this->purpose = $purpose ; } public function getInfo() { return $this->fuel.$this->purpose.'车'; } } class newcar extends Car { public $fuel; public $purpose; public function setFuel($fuel) { $this->fuel = $fuel; } public function setPurpose($purpose) { $this->purpose = $purpose ; } public function getInfo() { return $this->fuel.$this->purpose.'车'; } } $car = new Car(); $car->setFuel('汽油'); $car->setPurpose('家用'); echo $car->getInfo(); echo '<hr>'; $car = new newcar(); $car->setFuel('汽油1'); $car->setPurpose('家用2'); echo $car->getInfo();
运行实例 »
点击 "运行实例" 按钮查看在线实例