开发者

PHP Class Design question

I am trying to write Classes to show some people in my skill test. One of the questions is as follow:

Show how a child would call a parent's method. Show how overloading works. Indicate the syntax for class variables.

I think I got most of the question done but not sure what Indicate the syntax for class variables mean...Could someone explain it for me? Thanks a lot!

Class Phone{

 function __construct(){
     echo "This is the constructor";
 }

 protected function feature(){
  echo "Communication <br>";
 }
 }

 Class CellPhone extends CordlessPhone {
   private $brand;
   function __construct(){
  echo "<p style='color:red;'>Cell phone feature:</p>";
   }

   function __set($b, $value){
    if($value=="Apple"){
    $this->brand=$value." is awesome!";
    }elseif($value=="LG"){
    $this->brand=$value." is nice";
    }else{
    $this->brand="We only accept Apple and LG";
    }
   }

   function __get($brand){
    return "The brand: ".$this->brand."------";
    }

   public function feature(){
   parent::feature();
   echo "Play music<br>";
   echo "Surf internet<br>";
   }
 }

 Class CordlessPhone extends Phone {
   function __construt(){
  echo "<p style='color:red;'>开发者_C百科;Cordless phone feature:</p>";
   }
   public function feature(){
   parent::feature();
   echo "Cordless<br>";
   echo "Use Battery<br>";
   }
 }

 $phone=new CellPhone();
 $phone->feature();
 $phone->brand="LG";
 echo $phone->brand;


I think they mean class variables as properties for that class.

class A {
   private $b = TRUE; // This is the syntax for setting visibility, name and default value

   public function __construct() {
       echo $this->b; // this is how to access from within a method
   }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜