Webbserver - Love Blomberg

Show sourcecode

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

public_html/exercises/klasser/

ovn_klass1.php
ovn_klass2.php
ovn_klass3.php

ovn_klass3.php

58 lines ASCII Windows (CRLF)
<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>Klasser 1</title>
</head>
<body>
 <?php
class Ball {
  
// Properties
  
private $color '';
  private 
$radius 0;

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

  
// Methods
  
public function get_color() {
    return 
$this->color;
  }

 public function 
get_radius() {
  return 
$this->radius;
 }
}

class 
Football extends Ball {
 private 
$name '';

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

class 
Basketball extends Ball {
 private 
$pressure 0;

 public function 
__construct($color$radius$pressure) {
  
$this->pressure $pressure;
  
parent::__construct($color$radius);
 }
}

$boll1 = new Football("Blue"5"BAJEN");
$boll2 = new Basketball("Red"95);

echo 
$boll1->get_color();
echo 
$boll1->get_radius();
echo 
"<br>";
echo 
$boll2->get_color();
echo 
$boll2->get_radius();
?>
</body>
</html>