Source Code:
(back to article)
<?php interface Shape { public function getArea(); } interface Color { public function getColor(); } class Square implements Shape, Color { private $side; private $color; public function __construct($side, $color) { $this->side = $side; $this->color = $color; } public function getArea() { return $this->side * $this->side; } public function getColor() { return $this->color; } } $square = new Square(5, "red"); echo "The area of the square is: " . $square->getArea() . "\n"; echo "The color of the square is: " . $square->getColor() . "\n"; // Output: // The area of the square is: 25 // The color of the square is: red ?>
Result:
Report an issue