Blogger Information
Blog 10
fans 0
comment 1
visits 8325
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
接口技术的实现:规范用户类的成员和类型
夏涛的博客
Original
864 people have browsed it

<?php 

//接口

interface Demo1{

    const sitename='php中文网';

    public function show();//虚拟抽象方法

    public function message();//虚拟抽象方法

}

interface Demo2{

    public function hello();//虚拟抽象方法

}

//接口不允许实例化,便允许继承接口,并实现接口中的全部方法

class Test implements Demo1,Demo2{

    //实现Demo1中的show方法

    public function show(){

        return '站点名称是:'.self::sitename;

    }

    //实现Demo1中的message方法

    public function message(){

        return '站点域名是:www.php.cn';

    }

    //实现Demo1中的hello方法

    public function hello(){

        return self::sitename.'欢迎您~';

    }

}

$obj=new Test();

echo $obj->show();

echo '<hr>';

echo $obj->message();

echo '<hr>';

echo $obj->hello();


 ?>



Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
  • 1970-01-01 08:00:00