2

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;'>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;

1 Answer 1

3

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
   }

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.