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

Popular posts from this blog

GROUP BY Clause and HAVING Clause in PHP

Method Overriding in Traits in PHP

Mysqli database Connection and Display Table Data from Database