php class Fruit protected mType protected mColor Green public function

 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
<?php
class Fruit
{
protected $mType = ' ';
protected $mColor = 'Green';
public function getType()
{
return $this->mType;
}
final public function getColor()
{
return $this->mColor;
}
}
final class Apple extends Fruit {
protected $mType = ' ';
protected $mColor = 'Red';
final public function getColor2()
{
return "Apple:".$this->mColor;
}
}
$generalFruit = new Fruit();
$myApple = new Apple();
echo $generalFruit->getType().":".$generalFruit->getColor()
." ".$myApple->getType().":".$myApple->getColor();