天外天学习第二次作业

作业1:继承多态与接口

roar();
    $pig->roar();
    $monkey->roar();
}

roarcheck();

//接口

interface iTalkable
{
    function talk();
}

interface iPlayable
{
    function play();
}

abstract class people implements iTalkable,iPlayable
{
    abstract public function talk();
    abstract public function play();
}

class teacher extends people implements iTalkable,iPlayable
{
    public function talk()
    {
        echo "I am talking.\n";
    }

    public function play()
    {
        echo "I am playing.\n";
    }
}

$teacher = new teacher();
$teacher->talk();
$teacher->play();
运行截图
twthomework.PNG

作业2:trait

speak();
    }
}
class MyClass1
{
    use Mytrait;
    public function speak(){
        echo "speak from myclass1" . PHP_EOL;
        }
 }
 class MyClass2
 {  
    use Mytrait;
    public function speak(){    
        echo "speak from myclass2" . PHP_EOL;  
    } 
 }

 $myclass1 = new Myclass1();
 $myclass1->justtalk();

 $myclass2 = new Myclass2();
 $myclass2->justtalk();
运行截图
twthomework.PNG

你可能感兴趣的:(天外天学习第二次作业)