电脑运行主板,电脑运行基于主板,主板上有很多接品,网卡 声卡 PCI插槽等;
interface Pci//pci接口
{
public void open();
public void close();
}
class MainBoard//主板类
{
public void run()
{
System.out.println("mainboard run")
}
public void usepci(Pci p)
{
if(p!=null)
{
p.open
p.close
}
}
}
class NetCard implements Pci//网卡,继承Pci插槽
{
public void open()
{
System.out.println("netcard open")
}
public void close()
{
System.out.println("netcard close")
}
}
class SoundCard implements Pci//网卡,继承Pci插槽
{
public void open()
{
System.out.println("soundcard open")
}
public void close()
{
System.out.println("soundcard close")
}
}
class DongtaiDemo//动态 主函数
{
public static void main(String[] args)
{
MainBoard mb= new MainBoard();
mb.run();
mb.usepci(null);
mb.usepci(new NetCard());
mb.usepci(new SetCard());
}
}
|