Untitled
unknown
plain_text
a year ago
637 B
16
Indexable
<?php
// Parent class
abstract class Car {
public $name;
public function __construct($name) {
$this->name = $name;
}
abstract public function intro() : string;
}
// Child classes
class Audi extends Car {
public function intro() : string {
return "Choose German quality! I'm an $this->name!";
}
}
class Volvo extends Car {
public function intro() : string {
return "Proud to be Swedish! I'm a $this->name!";
}
}
$audi = new Audi("Audi");
echo $audi->intro();
echo "<br>";
$volvo = new Volvo("Volvo");
echo $volvo->intro();
echo "<br>";
?>Editor is loading...
Leave a Comment