<?php
class Fruit {
protected $name;
public function __construct($name) {
$this->name = $name;
}
protected function getName() {
return $this->name;
}
}
class Apple extends Fruit {
public function showName() {
return "This is an " . $this->getName(); // 可以访问父类的protected方法
}
}
$apple = new Apple("Apple");
echo $apple->showName(); // 输出:This is an Apple
顶一下
(0)
0%
踩一下
(0)
0%
- 相关评论
- 我要评论
-