-
Notifications
You must be signed in to change notification settings - Fork 0
/
inheritence.php
51 lines (35 loc) · 1007 Bytes
/
inheritence.php
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
<?php
include('errorReport.php');
class Fruit {
public $name;
public $color;
public function __construct($name, $color) {
$this->name = $name;
$this->color = $color;
}
protected function intro() {
echo "The fruit is {$this->name} and color is {$this->color}.";
}
}
class grape extends Fruit {
public function __construct($name, $color, $weight) {
$this->name = $name;
$this->color = $color;
$this->weight =$weight;
}
// public function message() {
// echo "am i a fruit or a grape";
// echo "<br>";
// $this->intro();
// }
public function intro() {
echo "The fruit is {$this->name}, the color is {$this->color} and weight is {$this->weight} gm";
}
}
$grape = new grape("Grape", "Green", "300");
// $grape->message();
echo "<br>";
$grape->intro();
// $pine = new Fruit("PineApple", "Yellow");
// $pine->intro();
?>