Advertisement
Yousuf1791

Code from oop book 2

Apr 16th, 2022
840
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.45 KB | None | 0 0
  1. <?php
  2.  
  3. class fruit{
  4.   public $name;
  5.   public $color;
  6.  
  7.   function set_name($n){
  8.     $this->name = $n;
  9.     echo $this->name;
  10.   }
  11.  
  12.   protected function set_color($c){
  13.     $this->color = $c;
  14.     echo $this->color;
  15.   }
  16. }
  17.  
  18. class fruit2 extends fruit{
  19.   public function get_color(){
  20.     echo $this->set_color();
  21.   }
  22. }
  23.  
  24. $obj = new fruit();
  25. echo $obj->set_name("Banana")."<br>";
  26.  
  27. $obj2 = new fruit2();
  28.  
  29. $obj2->set_name("Yellow");
  30.  
  31.  
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement