Ex.01,Ex.02 完了

This commit is contained in:
2026-10-21 12:49:39 +09:00
parent 261ff5f68b
commit 9aebbab0ab
2 changed files with 38 additions and 1 deletions

View File

@@ -1,5 +1,4 @@
<?php
/**
* [Ex01 継承とnamespaceを使った問題]
*
@@ -22,3 +21,26 @@
* d. 継承したメソッド run() と breathe() を実行し、結果を出力する。
*
*/
// require_once を使い "common/Animal.php" を読み込む。
require_once __DIR__ . '/common/Animal.php';
// b
use Common\Animal;
// b Animal~
class Ex01 extends Animal {
}
// "Ex01" のインスタンスを生成し、
$ex01 = new Ex01();
// setName() メソッドで名前に '人' をセットする
$ex01->setName('人');
// 継承したメソッド run() と breathe() を実行し、結果を出力する。
$ex01->run();
$ex01->breathe();