Classes and Objects in PHP OOPS
<?php
class TV
{
public $model = "xyz";
public $volume = 1;
//By default functions are public unless you define private or protected.
public function volumeUp()
{
$this->volume++;
}
public function volumeDown()
{
$this->volume--;
}
}
$tv_one = new TV();
$tv_two = new TV();
echo $tv_one->volume . "<br>";
echo $tv_two->volume . "<br>";
echo $tv_one->model . "<br>";
echo $tv_two->model . "<br>";
$tv_one->volumeUp();
echo $tv_one->volume . "<br>";
$tv_one->volumeDown();
echo $tv_one->volume . "<br>";
// OUTPUT :
//1
// 1
// xyz
// xyz
// 2
// 1
?>
Comments
Post a Comment