interface myusb{
function type();
function alert();
}class usb implements myusb{
function type(){
echo '2.0';
}
function alert(){
echo 'Found the usb device!';
}
}class mp3 implements myusb{
function type(){
echo '1.0';
}
function alert(){
echo 'Found the music device!';
}
}class mypc{
function device($what){
echo $what->type().'<br>';
echo $what->alert();
}
}$zip=new usb();
$music=new mp3();
$pc=new mypc();$pc->device($music);
?>
看视频编的个多态的例子,结果正确输出为
1.0
Found the music device!
是对的 但是
class usb implements myusb{行前面是个叉然后usb下面是波浪线, 我看了下提示是分析器错误,类名应该在关键字class后面!
我想是不是我的类名usb错了,然后改了个类名叫usb1最后叉没了波浪线也没了!
不明白为什么usb错了,类的命名规则不是跟变量的命名规则一样吗,usb又没违反变量的命名规则?
还望各位大侠指教,谢谢!
function type();
function alert();
}class usb implements myusb{
function type(){
echo '2.0';
}
function alert(){
echo 'Found the usb device!';
}
}class mp3 implements myusb{
function type(){
echo '1.0';
}
function alert(){
echo 'Found the music device!';
}
}class mypc{
function device($what){
echo $what->type().'<br>';
echo $what->alert();
}
}$zip=new usb();
$music=new mp3();
$pc=new mypc();$pc->device($music);
?>
看视频编的个多态的例子,结果正确输出为
1.0
Found the music device!
是对的 但是
class usb implements myusb{行前面是个叉然后usb下面是波浪线, 我看了下提示是分析器错误,类名应该在关键字class后面!
我想是不是我的类名usb错了,然后改了个类名叫usb1最后叉没了波浪线也没了!
不明白为什么usb错了,类的命名规则不是跟变量的命名规则一样吗,usb又没违反变量的命名规则?
还望各位大侠指教,谢谢!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货