package interfaceDemo;
interface Equipment_specifications{
	void DoWork();
}
class MBorad{//主板
	private  static  int index;//定义一个变量
	private static Equipment_specifications[] es=new Equipment_specifications[6];//创建一个长度为6的数组
	
	public static void  pluginIn( Equipment_specifications usb){
		if(index==es.length){
			System.out.println("设备接口已经插满!");
			return;
		}
		es[index]=usb;
		index++;
	}
	public static void Operation() {
		// TODO 自动生成的方法存根
		for(Equipment_specifications usb : es){
			if(usb != null){
				usb.DoWork();
			}
		}
	}
}
class Mouse implements Equipment_specifications{//USB鼠标

	@Override
	public void DoWork() {
		// TODO 自动生成的方法存根
		System.out.println("我在实现点击!");
	}
	
}
class Printer implements Equipment_specifications{//USB打印机

	@Override
	public void DoWork() {
		// TODO 自动生成的方法存根
		System.out.println("我在实现打印文字!");
	}
	
}
public class MotherBorad {

	public static void main(String[] args) {
		// TODO 自动生成的方法存根
		 MBorad.pluginIn(new Printer());
		 MBorad.pluginIn(new Mouse());
		 MBorad.pluginIn(new Mouse());
		 MBorad.pluginIn(new Mouse());
		 MBorad.pluginIn(new Mouse());
		 MBorad.pluginIn(new Mouse());
		 MBorad.pluginIn(new Mouse());
		 MBorad.Operation();
	
	}

}

 

相关文章:

  • 2021-12-28
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2021-04-08
  • 2021-09-06
  • 2021-04-27
  • 2021-07-21
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2023-02-01
  • 2021-04-03
  • 2022-12-23
相关资源
相似解决方案