php-ood接口和引用-139

<?php

//interface :类中全是抽象方法,不用加abstract关键字

//对象属性必须为常量

//接口的引用 implements:可以一次引用多个接口

//同时出现继承和接口时要先继承后接口,单继承多接口

//interface int2 extends int1接口的继承

interface testint1{

const NAME1='name1';

function int1();

function int2();

}

interface testint2{

const NAME2='name2';

function int3();

function int4();

}

class Book implements testint1,testint2{

function int1(){

echo'this is int1()'.'</br>';

   }

function int2(){

echo'this is int2()'.'</br>';

   }

function int3(){

echo'this is int3()'.'</br>';

   }

function int4(){

echo'this is int4()'.'</br>';

   }

}

class Mybook extends Book implements testint1{


}

$b=new Book();

$b->int1();

$b->int2();

$b->int3();

$b->int4();

echo Book::NAME1.'<br>';

echo Book::NAME2.'<br>';

$b1=new Mybook();

$b1->int1();

?>

http://localhost/php/23.php

this is int1()
this is int2()
this is int3()
this is int4()
name1
name2
this is int1()


本文出自 “yanzi” 博客,谢绝转载!

你可能感兴趣的:(PHP)