forked from shreenivasan/Tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolymorphism.php
More file actions
executable file
·59 lines (40 loc) · 909 Bytes
/
Copy pathpolymorphism.php
File metadata and controls
executable file
·59 lines (40 loc) · 909 Bytes
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
<?php
interface Shape{
public function getArea();
}
class Circle implements Shape{
private $radius;
public function setRadius($radius = 0){
$this->radis = $radius;
}
public function getRadius(){
return $this->radius;
}
public function getArea() {
$r = $this->getRadius();
return ' Area of circle ==> '.(3.14*$r*$r);
}
}
class Square implements Shape{
private $side;
public function setSide($side = 0){
$this->side = $side;
}
public function getSide(){
return $this->side;
}
public function getArea() {
$l = $this->getSide();
return ' Area of square ==> '.$l*$l;
}
}
function calculateArea(Shape $s){
return $s->getArea();
}
$c = new Circle();
$c->setRadius(10);
$sq = new Square();
$sq->setSide(20);
echo calculateArea($sq);
echo '<br>';
echo calculateArea($c);