Files
php-question/Question13-Inheritance/Ex01.php
2026-10-06 12:10:09 +09:00

25 lines
1.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* [Ex01 継承とnamespaceを使った問題]
*
* TODO:
* 1. 既に作成されている "common/Animal.php" を使用します。
* ※Animal.php は namespace Common を使用して定義されています。
* 仕様:
* - クラス名:Animal
* - プロパティ:private $name
* - メソッド:
* setName($name) : 名前をセットするセッター
* getName() : 名前を取得するゲッター
* run() : 「{name}は走る」と出力する
* breathe() : 「{name}は呼吸する」と出力する
*
* 2. 本ファイル内で、下記の処理を実装してください。
* a. require_once を使い "common/Animal.php" を読み込む。
* b. namespace を利用し、Animal クラスを継承したクラス "Ex01" を定義する。
* c. "Ex01" のインスタンスを生成し、setName() メソッドで名前に '人' をセットする。
* d. 継承したメソッド run() と breathe() を実行し、結果を出力する。
*
*/