문제

<?php
class main{
  public $bob="my name bob";
  private $lee="my surname lee";
  protected $david="my caste";
       function output(){
  $output=$this->lee;
   echo $output;
}
} class second extends main{ } $obj= new second; $obj->output();

?>

the output is 'my surname lee'. how ? i am confused with private and protected.please let me understand the working of it.and what is polymorphism in php any tutorial link or example.

도움이 되었습니까?

해결책

polymorphism in php is well explained here.

In one word: Polymorphism describes a pattern in object oriented programming in which classes have different functionality while sharing a common interface.

For your question: However the variable

$lee

is private, the function

function output()

is public and can be accessed outside.

And this page have more specific sinariao in the php programming language.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top