Show sourcecode
The following files exists in this folder. Click to view.
webbsrvprg1/exercises/ovning8/
index.php
40 lines UTF-8 Windows (CRLF)
<?php
class Boll {
protected $namn;
private $farg;
private $radie;
public function __construct($namn, $farg, $radie) {
$this->namn = $namn;
$this->farg = $farg;
$this->radie = $radie;
}
public function getInfo() {
echo "Bollen har en radie på <strong>$this->radie</strong> cm<br>samt färgen <strong>$this->farg</strong><br>";
}
}
class Fotboll extends Boll {
function sparka() {
echo "Bollen '$this->namn' sparkades!<br>";
}
}
$fotboll = new Fotboll("fotboll", "grön", 10);
$fotboll->getInfo();
$fotboll->sparka();
echo "<br>";
$boll = new Boll("fotboll", "vit", 15);
$boll->getInfo();
echo "<br>";
$boll = new Boll("fotboll", "gul", 5);
$boll->getInfo();
?>