diff --git a/Question13-Inheritance/Ex01.php b/Question13-Inheritance/Ex01.php index 81e4cf8..6ca90ae 100644 --- a/Question13-Inheritance/Ex01.php +++ b/Question13-Inheritance/Ex01.php @@ -1,5 +1,4 @@ setName('人'); + +// 継承したメソッド run() と breathe() を実行し、結果を出力する。 +$ex01->run(); +$ex01->breathe(); diff --git a/Question13-Inheritance/Ex02.php b/Question13-Inheritance/Ex02.php index a693c04..5549a55 100644 --- a/Question13-Inheritance/Ex02.php +++ b/Question13-Inheritance/Ex02.php @@ -18,3 +18,18 @@ * 5. その後、showParameter() メソッドを呼び出して、キャラクター情報を出力してください。 * */ +// 本ファイル内で、require_once を使い "/common/Hero.php" を読み込んでください。 +require_once __DIR__ . '/common/Hero.php'; + +// namespace を利用して、inheritance\common\Common\Hero クラスを使用 +// namespaceが書いてあれば呼び出し側はuseを使う必要がある +use inheritance\Common\Hero; + +// Common\Hero クラスのインスタンスを生成し、 +$hero = new Hero(); + +// setName() メソッドを使って名前に "勇者" を設定してください。 +$hero->setName('勇者'); + +// showParameter() メソッドを呼び出して、キャラクター情報を出力 +echo $hero->showParameter(); \ No newline at end of file