Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class People
- {
- private $name;
- private $age;
- private $growth;
- private $weight;
- public function __construct($name, $age, $growth, $weight) {
- $this->name = $name;
- $this->age = $age;
- $this->growth = $growth;
- $this->weight = $weight;
- }
- public function tellAboutYourself() {
- echo 'Hello, my name is ', $this->name,
- ". I'm ", $this->age, " years old, my growth is ",
- $this->growth, ', weight ', $this->weight;
- }
- }
- class Kate extends People
- {
- private $insalubrityLevel;
- public function __construct($age, $growth, $weight, $insalubrityLevel) {
- if ($insalubrityLevel < 100)
- echo 'Уровень вредности Кати не может быть меньше 100!';
- else if ($growth > 160 || $weight > 55)
- echo 'Вес и рост не должны превышать 55 и 160!';
- else {
- parent::__construct('Катя', $age, $growth, $weight);
- $this->insalubrityLevel = $insalubrityLevel;
- }
- }
- public function tellAboutYourself() {
- parent::tellAboutYourself();
- echo '. My insalubrity level is ', $this->insalubrityLevel;
- }
- }
- $Kate = new Kate(19, 159, 44, 999);
- $Kate->tellAboutYourself();
- // Короч этот весь код выведет:
- // Hello, my name is Катя. I'm 19 years old, my growth is 159, weight 44. My insalubrity level is 999
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement