Show sourcecode
The following files exists in this folder. Click to view.
webbserverprogrammering/exercises/klasser/
ovning_1.php
ovning_2.php
ovning_3.php
ovning_4.php
ovning_5.php
ovning_2.php
39 lines UTF-8 Windows (CRLF)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/dark.css">
<title>Övning 2</title>
</head>
<body>
<?php
class Ball {
public $name;
public $color;
public $radius;
function __construct($color, $radius) {
$this->color = $color;
$this->radius = $radius;
}
function get_color() {
return $this->color;
}
function get_radius() {
return $this->radius;
}
}
$brown_ball = new Ball("brun", 5);
$white_ball = new Ball("vit", 2);
$yellow_ball = new Ball("gul", 1);
echo "Boll nummer 1 är ".$brown_ball->get_color()." och har radien ".$brown_ball->get_radius()."cm<br>";
echo "Boll nummer 1 är ".$white_ball->get_color()." och har radien ".$white_ball->get_radius()."cm<br>";
echo "Boll nummer 1 är ".$yellow_ball->get_color()." och har radien ".$yellow_ball->get_radius()."cm";
?>
</body>
</html>