My question is this: If I can declare a constructor in a class abstract
and also in the child classes. And also how to access their values. For example:
abstract class Animal {
private $nome;
private $idade;
public funtion __construct($nome, $idade) {
$this->nome = $nome;
$this->idade = $idade;
}
}
And in the child class, which inherits from the Animal
class:
class Cachorro extends Animal {
private $corPelo;
public function __construct($corPelo) {
$this->corPelo = $corPelo;
}
}
And when I try to instantiate I call the class Cachorro
instantiating the values to Animal
:
$dog = new Cachorro('belinha', 4, 'preto');
However, this way I can not access the corPelo
of the child class Cachorro
, only the values of the parent class Animal
.
Am I doing wrong?