开始运行 ❯
获取您
自有的 PHP
服务器
×
更改方向
更改主题,黑暗/浅色
转到 Spaces
<!DOCTYPE html> <html> <body> <?php class Fruit { public $name; public $color; public function __construct($name, $color) { $this->name = $name; $this->color = $color; } protected function intro() { echo "The fruit is {$this->name} and the color is {$this->color}."; } } class Strawberry extends Fruit { public function message() { echo "Am I a fruit or a berry? "; } } // Try to call all three methods from outside class $strawberry = new Strawberry("Strawberry", "red"); // OK. __construct() is public $strawberry->message(); // OK. message() is public $strawberry->intro(); // ERROR. intro() is protected ?> </body> </html>
我属于水果还是浆果?