多态-II(接口实现)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>多态类</title> </head> <body> <?php interface Car{ public function say(); } class Bus implements Car{ public function say(){ echo "公交车"."<br>"; } } class Taxi implements Car{ public function say(){ echo "出租车"."<br>"; } } function say($obj){ if($obj instanceof Car){ $obj->say(); } } $bus=new Bus(); $taxi=new Taxi(); say($bus); //输出“公交车” say($taxi); //输出“出租车” ?> </body> </html>
如需转载,请注明文章出处,谢谢!!!