-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoop2.php
46 lines (40 loc) · 834 Bytes
/
oop2.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
<?php
class Fruit
{
public $name;
public $color;
public function __construct($name, $color)
{
$this->name = $name;
$this->color = $color;
$this->intro();
}
final protected function intro()
{
echo "The fruit is {$this->name} and the color is {$this->color}.";
}
}
// Strawberry is inherited from Fruit
class Strawberry extends Fruit
{
public function message()
{
echo "Am I a fruit or a berry? ";
}
public function intro()
{
echo "Second intro";
}
public function newIntro()
{
return $this->intro();
}
}
class mango extends Strawberry {}
$strawberry = new Strawberry("Strawberry", "red");
// $strawberry->message();
echo '<br>';
// $strawberry->intro();
$strawberry->newIntro();
echo '<br>';
echo '<br>';