Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbserverprogrammering/exercises/klasser/

ovning_1.php
ovning_2.php
ovning_3.php
ovning_4.php
ovning_5.php

ovning_5.php

52 lines UTF-8 Windows (CRLF)
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/dark.css">
  <title>Övning 5</title>
</head>
<body>
  <?php
    
class Ball {
      private 
$name;
      private 
$color;
      private 
$radius;

      function 
__construct($name$color$radius) {
        
$this->name $name;
        
$this->color $color;
        
$this->radius $radius;
      }

      public function 
intro() {
        echo 
$this->name." är ".$this->color." och har radien ".$this->radius."cm<br>";
      }
    }

    class 
BrownBall extends Ball {
      public function 
message() {
        echo 
"Den bruna bollen kanske inte är en boll😐";
      }
    }

    class 
RedBall extends Ball {

      public function 
message() {
        echo 
"Istället för bruna bollar har det kommit ut röda bollar på sistonde😖";
      }
    }

    
$brown_ball = new BrownBall("Boll 1""brun"5);
    
$red_ball = new RedBall("Boll 2""röd"2);

    
$brown_ball->intro();
    
$brown_ball->message();

    echo 
"<br><br>";

    
$red_ball->intro();
    
$red_ball->message();
  
?>
</body>
</html>