Result Size: 625 x 571
x
 
<!DOCTYPE html>
<html>
<body>
<?php
class Fruit {
  public $name;
  public $color;
  public function __construct($name, $color) {
    $this->name = $name;
    $this->color = $color; 
  }
  public function intro() {
    echo "The fruit is {$this->name} and the color is {$this->color}."; 
  }
}
class Strawberry extends Fruit {
  public $weight;
  public function __construct($name, $color, $weight) {
    $this->name = $name;
    $this->color = $color;
    $this->weight = $weight; 
  }
  public function intro() {
    echo "The fruit is {$this->name}, the color is {$this->color}, and the weight is {$this->weight} gram."; 
  }
}
$strawberry = new Strawberry("Strawberry", "red", 50);
$strawberry->intro();
?>
 
</body>
<!-- Mirrored from www.w3schools.com/php/phptryit.asp?filename=tryphp_inheritance4 by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 27 Jan 2020 02:50:49 GMT -->
</html>
×

Report a Problem: