php基礎語法11--面向對象的接口操作

<?php

// 使用 interface 用於定義接口,首先說明接口的,用於聲明基本接口,interface關鍵字定義接口

// 但是其中所有的方法都是空的,實現其中的方法需要在"類"中實現。

// 接口定義的所有方法都是公開的,這是接口的基本特性


interface hello{
    public function say1_0($a);
    public function say1_1($b);
}


// 實現接口需要在具體類中實現,需要使用
class hello_1 implements hello{  // 注意實現類不能與接口名重名
    public function say1_0($a)
    {
        // TODO: Implement say_0() method.
        echo "hello";


    }
    public function say1_1($b)
    {
        // TODO: Implement say_1() method.
        echo "天安門";
    }

}

?>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章