运行 ❯
获取您自己的
PHP 服务器
×
更改方向
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <?php class Fruit { public $name; public $color; public function __construct($name, $color) { $this->name = $name; $this->color = $color; } public function intro() { echo "The fruit is {$this->name} and the color is {$this->color}."; } } class Strawberry extends Fruit { public $weight; public function __construct($name, $color, $weight) { $this->name = $name; $this->color = $color; $this->weight = $weight; } public function intro() { echo "The fruit is {$this->name}, the color is {$this->color}, and the weight is {$this->weight} gram."; } } $strawberry = new Strawberry("Strawberry", "red", 50); $strawberry->intro(); ?> </body> </html>
水果是草莓,颜色是红色,重量是 50 克。