Show sourcecode
The following files exists in this folder. Click to view.
ovn_klass1.php
ovn_klass2.php
ovn_klass3.php
ovn_klass4.php
ovn_klass5.php
ovn_klass6.php
ovn_klass7.php
ovn_klass7.php
66 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
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Klasser 7</title>
</head>
<body>
<?php
class Boll {
private $färg;
private $radie;
private static $antal = 0;
public function __construct($färg, $radie) {
$this->färg = $färg;
$this->radie = $radie;
self::$antal++;
}
public function getFärg(){
echo "Bollen är ". $this->färg. "<br>";
}
public function getRadie(){
echo "Radien är ".$this->radie. "<br>";
}
public function info() {
echo "Bollar!!";
}
public static function antalInfo() {
return self::$antal;
}
}
class Fotboll extends Boll {
public function info() {
echo "Andra bollar!!";
}
}
class Badboll extends Boll {
public function info() {
echo "Andra bollar!!";
}
}
$Fotboll1 = new Fotboll("Vit", "7");
$badboll1 = new Badboll("blå", "8");
$badboll2 = new Badboll("blå", "8");
$bollLista = array($Fotboll1, $badboll1, $badboll2);
foreach ($bollLista as $boll) {
$boll->getFärg();
$boll->getRadie();
echo "<br>";
}
echo "Det finns ".Boll::antalInfo(). " bollar."
?>
</body>
</html>