From 9aebbab0ab4508c5615c6e2836743d33d0155733 Mon Sep 17 00:00:00 2001 From: m-takatsuki <26-m-takatsuki-webstar@it-college.co.jp> Date: Wed, 21 Oct 2026 12:49:39 +0900 Subject: [PATCH] =?UTF-8?q?Ex.01,Ex.02=E3=80=80=E5=AE=8C=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Question13-Inheritance/Ex01.php | 24 +++++++++++++++++++++++- Question13-Inheritance/Ex02.php | 15 +++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) 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