批改状态:合格
老师批语:
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/5/9 0009
* Time: 20:09
*/
if (!class_exists('Animal')) {
class Animal
{
protected $name;
public function __construct($name = '狗')
{
$this->name = $name;
}
public function eat($meat = '肉')
{
return $this->name . '吃' . $meat;
}
}
}
if (!trait_exists('pl')) {
trait pl
{
public $name2 = '猫';
public function fit($fit = '打架')
{
return $this->name . '和' . $this->name2 . '在草地上' . $fit;
}
abstract public static function hobby($name2);
public function eat($fruit = '香蕉')
{
return $this->name . '吃' . $fruit;
}
}
}
class pig extends Animal
{
use pl;
protected $name = '猪';
public static function hobby($name)
{
return $name;
}
public function eat($fruit = '菠萝')
{
return $this->name . '吃' . $fruit;
}
}
$pig = new pig();
echo $pig->eat();点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号