Encapsulation in PHP OOPS
<?php
//After creating Object, only public property can be accessed,not private and not protected.
class TV
{
protected $model;
private $volume;
public function volumeUp()
{
$this->volume++;
}
protected function getModel()
{
return $this->model;
}
public function volumeDown()
{
$this->volume--;
}
public function __construct($m, $v)
{
$this->model = $m;
$this->volume = $v;
}
}
class Plazma extends TV
{
public function getModel()
{
return $this->model;
}
}
$tv = new Plazma("abc", 1);
echo $tv->getModel();
// OUTPUT :
//abc
?>
Comments
Post a Comment