Show sourcecode
The following files exists in this folder. Click to view.
webbserverprogrammering/exercises/classes/
classes.php
classes1.php
classes2.php
classes3.php
classes4.php
classes5.php
classes4.php
93 lines UTF-8 Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Klasser 4</title>
</head>
<body>
<?php
class Ball_d {
// Egenskaper
private $color;
private $radius;
// Metoder
public function __construct($color, $radius) {
$this->color = $color;
$this->radius = $radius;
}
public function get_color() {
return $this->color;
}
public function get_radius() {
return $this->radius;
}
}
class Ball_e extends Ball_d {
// Egenskaper
private $weight;
// Metoder
public function __construct($color, $radius, $weight) {
parent::__construct($color, $radius);
$this->weight = $weight;
}
public function get_weight() {
return $this->weight;
}
}
class Ball_f extends Ball_d {
// Egenskaper
private $material;
// Metoder
public function __construct($color, $radius, $material) {
parent::__construct($color, $radius);
$this->material = $material;
}
public function get_material() {
return $this->material;
}
}
// Boll 1
$ball_1 = new Ball_d("Grön", "1 dm");
echo "Boll 1";
echo "<hr style=\"border: none; border-top: 2px dotted black; width: 200px; margin-left: 0;\">";
echo "Färg: " . $ball_1->get_color() . "<br>";
echo "Radie: " . $ball_1->get_radius(). "<br>";
echo "<hr style=\"width: 200px; margin-left: 0;\">" . "<br>";
// Boll 2
$ball_2 = new Ball_e("Röd", "2 dm", "1 kg");
echo "Boll 2";
echo "<hr style=\"border: none; border-top: 2px dotted black; width: 200px; margin-left: 0;\">";
echo "Färg: " . $ball_2->get_color() . "<br>";
echo "Radie: " . $ball_2->get_radius(). "<br>";
echo "Vikt: " . $ball_2->get_weight(). "<br>";
echo "<hr style=\"width: 200px; margin-left: 0;\">" . "<br>";
// Boll 3
$ball_3 = new Ball_f("Blå", "4 dm", "Tungsten");
$weight_3 = new Ball_e("N/A", "N/A", "5172 kg");
echo "Boll 3";
echo "<hr style=\"border: none; border-top: 2px dotted black; width: 200px; margin-left: 0;\">";
echo "Färg: " . $ball_3->get_color() . "<br>";
echo "Radie: " . $ball_3->get_radius(). "<br>";
echo "Vikt: ". $weight_3->get_weight() . "<br>";
echo "Material: " . $ball_3->get_material(). "<br>";
echo "<hr style=\"width: 200px; margin-left: 0;\">" . "<br>";
?>
</body>
</html>