age = 0;
$this->weight = 100;
}
// define methods
public function eat($units) {
echo $this->name." is eating ".$units." units of food...
";
$this->weight += $units;
}
public function run() {
echo $this->name." is running...
";
}
public function kill() {
echo $this->name." is killing prey...
";
}
public function sleep() {
echo $this->name." is sleeping...
";
}
}
// extended class definition
class PolarBear extends Bear {
// constructor
public function __construct() {
parent::__construct();
$this->colour = "white";
$this->weight = 600;
}
// define methods
public function swim() {
echo $this->name." is swimming...
";
}
}
// extended class definition
class GrizzlyBear extends Bear {
// constructor
public function __construct() {
parent::__construct();
$this->colour = "gray";
$this->weight = 800;
}
// define methods
public function roars() {
return true;
}
}
$bear = new Bear();
$bear->name = "Yogi";
echo "
"; var_dump($bear); echo ""; $bear->run(); $bear->kill(); $bear->sleep(); $bear->eat(100); echo $bear->name." now weighs ".$bear->weight; $polar_bear = new PolarBear(); $polar_bear->name = "Nanuk"; echo "
"; var_dump($polar_bear); echo ""; $polar_bear->swim(); $grizzly_bear = new GrizzlyBear(); $grizzly_bear->name = "Kodiak"; echo "
"; var_dump($grizzly_bear); echo ""; echo $grizzly_bear->name; if ($grizzly_bear->roars()) { echo " is roaring...