-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathheritage.php
More file actions
47 lines (45 loc) · 1.4 KB
/
heritage.php
File metadata and controls
47 lines (45 loc) · 1.4 KB
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
<?php
class Valeur{
protected $nom;
protected $prix;
function __construct($nom,$prix){
$this->nom=$nom;
$this->prix=$prix;
}
function getinfo(){
$info="<h4>Le prix de $this->nom est de $this->prix</h4><br/>";
return $info;
}
}
//class derivee
class Action extends Valeur{
public $bourse;
public function __construct($nom,$prix,$bourse){
parent::__construct($nom,$prix);//utilise le constructeur du parrent
$this->bourse=$bourse;
}
//redefinition
public function getinfo(){
$info="<h3>Action $this->nom cotee a la bourse $this->bourse</h3>";
$info.=parent::getinfo();
return $info;
}
}
//deuxieme class derivee
class Emprunt extends Valeur{
public $taux;
public function __construct($nom,$prix,$taux){
parent::__construct($nom,$prix);
$this->taux=$taux;
}
public function getinfo(){
$info="<h2>Les genies du $this->taux et du $this->nom</h2>";
$info.=parent::getinfo();//appel de la methode ecrite dans parent et concatenation
return $info;
}
}
$act1=new Action('Elisee','20$','Ndola');
echo $act1->getinfo();
$emprunt=new Emprunt('Mizkael','20$','5');
echo $emprunt->getinfo();
?>