sir when we un-comment the getModel method in child class and execute it dispaly error private property can not access in child but in get_Display method same propety is access how is it possible or i m making a mistake?
class Tv{
public $volume;
private $model;
function volume_up(){
$this->volume++;
}
function __construct($m,$v){
$this->model=$m;
$this->volume=$v;
}
function getModel(){
return $this->model;
}
}
$obj=new Tv('xyz',10);
//$obj->model;//error can not access private property
echo $obj->getModel();// can access private property
class Plazma extends Tv {
/*function getModel(){
return $this->model;
}*/
function get_Display( ){
return $this->model='AXN';
}
}
$obj2=new Plazma('xyz',10);
//$obj->model;//error can not access private property
// $obj2->getModel();// can access private property
echo $obj2->get_Display('ANX');
?>
What I have tried:
class Tv{
public $volume;
private $model;
function volume_up(){
$this->volume++;
}
function __construct($m,$v){
$this->model=$m;
$this->volume=$v;
}
function getModel(){
return $this->model;
}
}
$obj=new Tv('xyz',10);
//$obj->model;//error can not access private property
echo $obj->getModel();// can access private property
class Plazma extends Tv {
/*function getModel(){
return $this->model;
}*/
function get_Display( ){
return $this->model='AXN';
}
}
$obj2=new Plazma('xyz',10);
//$obj->model;//error can not access private property
// $obj2->getModel();// can not access private property
echo $obj2->get_Display('ANX'); // but here private property is access why ?
?>