Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.36 KB | None | 0 0
  1. <?php
  2.    
  3. class People
  4. {
  5.     private $name;
  6.     private $age;
  7.     private $growth;
  8.     private $weight;
  9.  
  10.     public function __construct($name, $age, $growth, $weight) {
  11.         $this->name = $name;
  12.         $this->age  = $age;
  13.         $this->growth = $growth;
  14.         $this->weight = $weight;
  15.     }
  16.  
  17.     public function tellAboutYourself() {
  18.         echo 'Hello, my name is ', $this->name,
  19.               ". I'm ", $this->age, " years old, my growth is ",
  20.               $this->growth, ', weight ', $this->weight;
  21.     }
  22. }
  23.  
  24. class Kate extends People
  25. {
  26.     private $insalubrityLevel;
  27.  
  28.     public function __construct($age, $growth, $weight, $insalubrityLevel) {
  29.  
  30.         if ($insalubrityLevel < 100)
  31.             echo 'Уровень вредности Кати не может быть меньше 100!';
  32.  
  33.         else if ($growth > 160 || $weight > 55)
  34.             echo 'Вес и рост не должны превышать 55 и 160!';
  35.  
  36.         else {
  37.             parent::__construct('Катя', $age, $growth, $weight);
  38.             $this->insalubrityLevel = $insalubrityLevel;
  39.         }
  40.     }
  41.  
  42.     public function tellAboutYourself() {
  43.         parent::tellAboutYourself();
  44.         echo '. My insalubrity level is ', $this->insalubrityLevel;
  45.     }
  46. }
  47.  
  48. $Kate = new Kate(19, 159, 44, 999);
  49.  
  50. $Kate->tellAboutYourself();
  51.  
  52. // Короч этот весь код выведет:
  53. // Hello, my name is Катя. I'm 19 years old, my growth is 159, weight 44. My insalubrity level is 999
  54.  
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement