Hi. I'm just a starter on php, i would like to ask on how to display the string that I assigned in my constructor.
Car.php
class Car {
private $color;
private $horsepower;
private $seats;
public function getColor() {
return $this->color;
}
public function setColor($color) {
$this->color = $color;
}
public function getHorsepower() {
return $this->horsepower;
}
public function setHorsepower($horsepower) {
$this->horsepower = $horsepower;
}
public function getSeats() {
return $this->seats;
}
public function setSeats($seats) {
$this->seats = $seats;
}
}
RaceCar.php
class RaceCar extends Car {
function __construct() {
$this->setColor("red");
$this->setHorsepower("23");
$this->setSeats("four");
}
}
and the index.php where I call them,
index.php
<body>
<?php
include_once('Car.php');
include_once('RaceCar.php');
$raceCar = new RaceCar();
echo "color: " + $raceCar->getColor();
echo "horsepower: " + $raceCar->getHorsepower();
echo "seats: " + $raceCar->getSeats();
?>
</body>