Show sourcecode
The following files exists in this folder. Click to view.
class.html
ovn_class1.php
ovn_class2.php
ovn_class3.php
ovn_class4.php
ovn_class2.php
58 lines UTF-8 Windows (CRLF)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Boll Program</title>
</head>
<body>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
class Boll {
public $farg;
public $radie;
public function __construct($farg = null, $radie = null) {
$this->farg = $farg;
$this->radie = $radie;
}
public function sattFarg($nyFarg) {
$this->farg = $nyFarg;
}
public function sattRadie($nyRadie) {
$this->radie = $nyRadie;
}
public function hamtaInfo() {
return "Bollen har färgen $this->farg och radien $this->radie cm.";
}
}
$boll1 = new Boll("röd", 10); // Boll med färg och radie
$boll2 = new Boll(); // Boll utan färg och radie
$boll3 = new Boll("gul"); // Boll med bara färg
$boll2->sattFarg("grön");
$boll2->sattRadie(20);
$boll3->sattRadie(15);
echo $boll1->hamtaInfo();
echo "<br>";
echo $boll2->hamtaInfo();
echo "<br>";
echo $boll3->hamtaInfo();
?>
</body>
</html>