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_3.php
36 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 3</title>
</head>
<body>
<?php
class Ball {
private $name;
public $color;
public $radius;
function __construct($name, $color, $radius) {
$this->name = $name;
$this->color = $color;
$this->radius = $radius;
}
public function intro() {
echo $this->name." är ".$this->color." och har radien ".$this->radius."cm<br>";
}
}
$brown_ball = new Ball("Boll 1", "brun", 5);
$white_ball = new Ball("Boll 2", "vit", 2);
$yellow_ball = new Ball("Boll 3", "gul", 1);
$brown_ball->intro();
$white_ball->intro();
$yellow_ball->intro();
?>
</body>
</html>