【发布时间】:2021-12-23 19:27:56
【问题描述】:
我正在研究与此问题稍有相似的其他问题。我试图做的是创建一个具有私有属性的类(或者不知道到底是什么)并私有存储在一个类中,然后像这样进行继承:
(我想进一步澄清我的解释,但我在编程中的词汇量非常有限)
<?php
class Fruit {
private $name;
private $color;
public function patients($name, $color) {
$this->name = $name;
$this->color = $color;
}
public function intro() {
echo "The fruit is {$this->name} and the color is {$this->color}.";
}
}
// Strawberry is inherited from Fruit
class Strawberry extends Fruit {
public function message() {
echo $this->intro();
}
}
$strawberry = new Strawberry("Strawberry", "red");
$strawberry->message();
?>
【问题讨论】:
标签: php oop inheritance