- interface PCI
- {
- public void open();
- public void close();
- }
- class MainBoard
- {
- public void run()
- {
- System.out.println("mainboard run");
- }
- public void usePCI(PCI p)//PCI p = new NetCard()
-
- {
- if(p!=null)
- {
- p.open();//这里面的open和close 与上面PCI里面的是什么关系?
- p.close();
- }
- }
- }
- class NetCard implements PCI
- {
- public void open()
- {
- System.out.println("netcard open");
- }
- public void close()
- {
- System.out.println("netcard close");
- }
- }
- class DuoTaiDemo5
- {
- public static void main(String[] args)
- {
- MainBoard mb = new MainBoard();
- mb.run();
- mb.usePCI(null);
- mb.usePCI(new NetCard());
复制代码 |
|