运行 ❯
获取您自己的
PHP
服务器
×
更改方向
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <?php // Parent class abstract class Car { public $name; public function __construct($name) { $this->name = $name; } abstract public function intro() : string; } // Child classes class Audi extends Car { public function intro() : string { return "Choose German quality! I'm an $this->name!"; } } class Volvo extends Car { public function intro() : string { return "Proud to be Swedish! I'm a $this->name!"; } } class Citroen extends Car { public function intro() : string { return "French extravagance! I'm a $this->name!"; } } // Create objects from the child classes $audi = new audi("Audi"); echo $audi->intro(); echo "<br>"; $volvo = new volvo("Volvo"); echo $volvo->intro(); echo "<br>"; $citroen = new citroen("Citroen"); echo $citroen->intro(); ?> </body> </html>
选择德国品质!我是奥迪!
为自己是瑞典人感到自豪!我是沃尔沃!
法国奢华!我是雪铁龙!