碧浪滔天
2017-04-18 11:30
<?php class Human{ public $name; public $height; public $weight; public function eat($food){ echo $this->name."'s eating".$fond."<br>"; } } class NbaPlayer extends Human { public $team; public $playerNumber; function __construct($name,$height,$weight,$team,$playerNumber){ //$this是php里面的伪变量,表示对象本身。 //可以通过$this->的方式访问对象的属性和方法。 $this->name = $name; $this->height = $height; $this->weight = $weight; $this->team = $team; $this->playerNumber = $playerNumber; } public function run(){ echo "Running\n"; } public function jump(){ echo "Jumping\n"; } } $player = new NbaPlayer("Jordan","198cm","98kg","BUll","23"); echo $player->name."<br>"; $player->eat("Apple"); ?>
看清楚你第七行是什么,应该是$food,不是$fond
哈哈,知道了
PHP面向对象编程
70189 学习 · 368 问题
相似问题