PHP基礎------抽象類別------介面

來源:互聯網
上載者:User

標籤:

<?phpheader("content-type:text/html; charset=utf-8");//抽象類別,抽象類別不能被執行個體化,抽象方法不能有方法體,只能由子類繼承去實現,抽象方法用abstract修飾abstract class Person{    abstract function eat();    abstract function say();}class son extends Person{    function eat()    {        echo "我能吃";    }    function say()    {        echo "我能說話";    }}$p = new son();$p->say();

 

<?php/*介面 * 是一種特殊的抽象類別,方法全部是抽象方法,屬性全部都是常量 * 只能被子類來實現,自身不能執行個體化 * 可以子類來實現多個介面 * */  interface Person {     const NAME="aaa";    //介面內預設的方法都是抽象方法     function eat();    function say(); }  class son implements Person {     function eat()    {        echo "吃";    }        function say()    {        echo "說";    } }$s = new son();$s->eat();?>

PHP基礎------抽象類別------介面

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.