Show sourcecode
The following files exists in this folder. Click to view.
public_html/exercises/klasser/
ovn_klass1.php
ovn_klass2.php
ovn_klass3.php
ovn_klass1.php
45 lines ASCII Windows (CRLF)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Klasser 1</title>
</head>
<body>
<?php
class Ball {
// Properties
public $color = '';
public $radius = 0;
// Methods
function set_color($color) {
$this->color = $color;
}
function get_color() {
return $this->color;
}
function set_radius($radius) {
$this->radius = $radius;
}
function get_radius() {
return $this->radius;
}
}
$boll1 = new Ball();
$boll2 = new Ball();
$boll1->set_color('blue');
$boll1->set_radius(5);
$boll2->set_radius(5);
$boll2->set_color('yellow');
echo $boll1->get_color();
echo $boll1->get_radius();
echo "<br>";
echo $boll2->get_color();
echo $boll2->get_radius();
?>
</body>
</html>