Access Modifier
<?php
// PUBLIC ACCESS MODIFIER
// class Base
// {
// public $name;
// public function __construct($n)
// {
// $this->name = $n;
// }
// public function show()
// {
// echo "Your Name : " . $this->name . "<br>";
// }
// }
// $test = new Base("Yahoo Baba");
// $test->name = "Baba Yahoo";
// $test->show();
// PROTECTED ACCESS MODIFIER
// class Base
// {
// protected $name;
// public function __construct($n)
// {
// $this->name = $n;
// }
// protected function show()
// {
// echo "Your Name : " . $this->name . "<br>";
// }
// }
// class Derived extends Base
// {
// public function get()
// {
// echo "Your Name is : " . $this->name . "<br>";
// }
// }
// $test = new Derived("Yahoo Baba");
// // $test->name = "Baba Yahoo";
// $test->get();
// PRIVATE ACCESS MODIFIER
class Base
{
private $name;
public function __construct($n)
{
$this->name = $n;
}
protected function show()
{
echo "Your Name : " . $this->name . "<br>";
}
}
class Derived extends Base
{
public function get()
{
echo "Your Name is : " . $this->name . "<br>";
}
}
$test = new Derived("Yahoo Baba");
$test->name = "Baba Yahoo";
$test->get();
?>
Comments
Post a Comment