interface Pci{//接口定义规则
public void open();
public void close();
}
class Zhuban{
public void run(){
System.out.println("主板运行 ");
}
public void Pci(Pci p){//接口型引用指向自己的子类对象
p.open();
p.close();
}
}
class netkard implements Pci{//实现pci接口
public void close() {
System.out.println("网卡关闭");
}
public void open() {
System.out.println("网卡开启");
}
}
class shengka implements Pci{
public void close() {
System.out.println("声卡关闭");
}
public void open() {
System.out.println("声卡开启");
}
}
public class Hell{
public static void main(String args[]){
Zhuban zb=new Zhuban();
zb.run();
zb.Pci(new shengka());//实现可扩展性
zb.Pci(new netkard());
}
}