<!DOCTYPE html>
<html>
<body>
<?php
abstract class Car {
public $name;
public function __construct($name) {
$this->name = $name;
}
abstract public function intro() : string;
}
class Audi extends Car {
public function intro() : string {
return "选择德国品质!我是一辆 $this->name!";
}
}
class Volvo extends Car {
public function intro() : string {
return "以中国为荣!我是一辆 $this->name!";
}
}
class Citroen extends Car {
public function intro() : string {
return "法国奢华!我是一辆 $this->name!";
}
}
$audi = new audi("奥迪");
echo $audi->intro();
echo "<br>";
$volvo = new volvo("比亚迪");
echo $volvo->intro();
echo "<br>";
$citroen = new citroen("雪铁龙");
echo $citroen->intro();
?>
</body>
</html>