- public class DuoTaiDemo5 {
-
- interface PCI{
- public void open();
- public void close();
-
- }
-
- class NetCard implements PCI{
- public void open(){
- System.out.println("网卡运行");
- }
- public void close(){
- System.out.println("网卡关闭");
- }
-
- }
- class SoundCard implements PCI{
- public void open(){
- System.out.println("声卡运行");
- }
- public void close(){
- System.out.println("声卡关闭");
- }
-
- }
- class MainBoard{
- public void run(){
- System.out.println("主板运行");
- }
- public void usePCI(PCI p){
- if(p != null)
- {
- p.open();
- p.close();
- }
- }
- }
- public static void main(String[] args) {
- MainBoard mb = new MainBoard();
- mb.run();
- mb.usePCI(new NetCard());
- mb.usePCI(new SoundCard());
- }
- }
复制代码
大家帮看一下,MainBoard mb = new MainBoard(); 这句话为什么一直报错呢? |
|