我在做作业的时候,偶然发现实现接口的类居然可以和继承了父类的子类用法差不多,于是我试着用instansof输出的是ture,那接口是可以称为实现接口的父类吗?public class Zhuangpei { public void contrl(PCI_interface ctr){
ctr.start();
}
public static void main(String args[]){
Zhuangpei ad = new Zhuangpei();
PCI_interface xk = new Xianka();
Shengka sk = new Shengka();
ad.contrl(xk); //调用start方法
System.out.println(xk instanceof PCI_interface);
System.out.println(sk instanceof PCI_interface);[/color]
}
}//实现PCI接口的的显卡类
public class Xianka implements PCI_interface {
public void start(){
System.out.println("this xianka");
}
public void stop(){
System.out.println("显卡停止工作");
}}
//接口
public interface PCI_interface {
void start();
void stop();
}
ctr.start();
}
public static void main(String args[]){
Zhuangpei ad = new Zhuangpei();
PCI_interface xk = new Xianka();
Shengka sk = new Shengka();
ad.contrl(xk); //调用start方法
System.out.println(xk instanceof PCI_interface);
System.out.println(sk instanceof PCI_interface);[/color]
}
}//实现PCI接口的的显卡类
public class Xianka implements PCI_interface {
public void start(){
System.out.println("this xianka");
}
public void stop(){
System.out.println("显卡停止工作");
}}
//接口
public interface PCI_interface {
void start();
void stop();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货