各位大神,我这是哪错了?

<?php


class Human{

public $name;

public $height;

public $weight;

private $age=40;//只能在类的内部被访问


public function eat($foot){

echo $this->name."'s eating ".$foot."<br>";

}


}

class NbaPlay extends Human{


public $team = "Bull";

public $playerNumber='23';

function __construct($name,$height,$weight,$team,$playerNumber){

echo "in nabplay"."<br>";

$this->name = $name;//$this是php里的伪变量表示对象自身。可以通过$this->的方式访问对象的属性和方法。

$this->height = $height;

$this->weight = $weight;

$this->team = $team;

$this->playerNumber = $playerNumber;

}


function __destruct(){

echo "lllll".$this->team."<br>";

}


public function run(){

echo "Running\n";

}

public function jump(){

echo "Jumping\n";

}

public function dribble(){

echo "Dribbleing\n";

}

public function shoot(){

echo "Shooting\n";

}

public function dunk(){

echo "Dunking\n";

}

public function pass(){

echo "Passing\n";

}

public function getAge(){

echo $this->name."年龄是".$this->age."<br>";

}

}


$jordan = new NbaPlay('jordan','180cm','160kg','lcl','24');

$jordan->getAge();

echo "<br>";

 


caidick
浏览 1390回答 2
2回答

坚强

将Human类中的private $age 改成 public $age

qq_大寒_2

private $age=40;//只能在类的内部被访问 public $age-40;
打开App,查看更多内容
随时随地看视频慕课网APP