Advertisement
destr0y

Untitled

Apr 11th, 2020
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. <html lang="ru">
  2. <head>
  3.     <title>ТиОПО</title>
  4.     <meta charset="utf-8">
  5. </head>
  6. </html>
  7. <?php
  8. class Product {
  9.     public $weight;
  10.     public $price;
  11.  
  12.     function About() {
  13.         return "Вес: $this->weight Цена: $this->price";
  14.     }
  15. }
  16.  
  17. class milkProduct extends Product {
  18.     public $some_name;
  19.  
  20.     public function __construct($weight, $price, $name)
  21.     {
  22.         $this->weight = $weight;
  23.         $this->price = $price;
  24.         $this->some_name = $name;
  25.     }
  26. }
  27.  
  28. class chocolateProduct extends Product {
  29.     public $some_name;
  30.  
  31.     public function __construct($weight, $price, $name)
  32.     {
  33.         $this->weight = $weight;
  34.         $this->price = $price;
  35.         $this->some_name = $name;
  36.     }
  37. }
  38.  
  39. class candyProduct extends Product {
  40.     public $some_name;
  41.  
  42.     public function __construct($weight, $price, $name)
  43.     {
  44.         $this->weight = $weight;
  45.         $this->price = $price;
  46.         $this->some_name = $name;
  47.     }
  48. }
  49.  
  50. $milk = new milkProduct('123', '321', 'КРЯ1');
  51. $chocolate = new chocolateProduct('321', '123', 'КРЯ2');
  52. $candy = new candyProduct('567', '765', 'КРЯ3');
  53.  
  54. echo $milk->some_name." | ".$milk->About()."<br/>";
  55. echo $chocolate->some_name." | ".$chocolate->About()."<br/>";
  56. echo $candy->some_name." | ".$candy->About()."<br/>";
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement