I am very new to OOP and trying to figure it out. I have the following code for a Mammal class which I plan to develop further. I have a child class Bear that echoes the correct values, but I can't over-write the $name, $move, $ear, or $sound values in the subclass Grizzly.
abstract class Mammal
{
protected $name;
protected $limbs;
protected $offspring = 'live';
protected $move;
protected $eat;
protected $sound;
protected function __construct($name, $limbs, $offspring, $move, $eat, $sound) {
$this->name = $name;
$this->limbs = $limbs;
$this->offspring = $offspring;
$this->move = $move;
$this->eat = $eat;
$this->sound = $sound;
}
public function getOutput() {
echo "The {$this->name} has four {$this->limbs}. The offspring is birthed {$this->offspring} and move by {$this->move}. They eat {$this->eat} and talk by {$this->sound}.";
}
}
class Bear extends Mammal
{
public function __construct() {
Mammal::__construct('bear', 'claws', $this->offspring, '', '', '');
}
}
class Grizzly extends Bear
{
public function __construct() {
Bear::__construct('grizzly bear', 'claws', $this->offspring, 'lumbering', 'salmon', 'roaring');
}
}
$grizzly = new Grizzly;
$grizzly->getOutput();
The output I am trying to get is: "The grizzly bear has four claws. The offspring is birthed live and move by lumbering. They eat salmon and talk by roaring." I appreciate any help!