多态-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>
上一篇:ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction解决办法


下一篇:pymysql.err.InternalError: (1205, 'Lock wait timeout exceeded; try restarting transaction')错误处理