php 教程-php 介面的聲明與使用

來源:互聯網
上載者:User

 第七章(13)物件導向詳解_介面的聲明與使用
interface 介面名稱{所有的屬性都必須是常量,所有的方法都必須是抽象的,所有的成員都必須是公有的}
介面的作用:是一個規範.
實現介面時使用implements<繼承介面的關鍵字>.
可以使用抽象類別去實現一個介面的部分方法.
使用類去實現介面中的全部方法.
介面的使用執行個體:
interface<聲明介面的關鍵字> Ren1
{
 const XINGMING="張三";
 function shuohua1();
 function shuohua2();
}
interface Ren2 extends<介面繼承介面可以使用繼承關鍵字> Ren1
{
 function shuohua3();
 function shuohua4();
}
interface Ren3{function shuohua5();}
interface Ren4{function shuohua6();}
class Ren5{function shuohua7(){echo "7777<br>";}}
class Ren extends Ren5 implemenrs<繼承介面的關鍵字,必須先繼承類再繼承介面,可以同時繼承多個介面> Ren2,Ren3,Ren4
{
 function shuohua1(){echo "1111<br>";}
 function shuohua2(){echo "2222<br>";}
 function shuohua3(){echo "3333<br>";}
 function shuohua4(){echo "4444<br>";}
 function shuohua5(){echo "5555<br>";}
 function shuohua6(){echo "6666<br>";}
<完整所有繼承過來的抽象方法>
}
$r=new Ren(); echo Ren::XINGMING."<br>";
$r->shuohua1();  $r->shuohua2();  $r->shuohua3();  $r->shuohua4();  $r->shuohua5();  $r->shuohua6();  $r->shuohua7();
執行個體輸出結果:
張三    1111    2222    3333    4444    5555    6666    7777

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.