运行 ❯
获取您自己的
PHP
服务器
×
更改方向
更改主题,深色/浅色
转到 Spaces
<!DOCTYPE html> <html> <body> <?php abstract class ParentClass { // Abstract method with an argument abstract protected function prefixName($name); } class ChildClass extends ParentClass { public function prefixName($name) { if ($name == "John Doe") { $prefix = "Mr."; } elseif ($name == "Jane Doe") { $prefix = "Mrs."; } else { $prefix = ""; } return "{$prefix} {$name}"; } } $class = new ChildClass; echo $class->prefixName("John Doe"); echo "<br>"; echo $class->prefixName("Jane Doe"); ?> </body> </html>
约翰·杜
简·杜