Java 接口实际应用代码
2024-09-04 18:44:35
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(); } }
最新文章
- 关于Android多项目依赖在Eclipse中无法关联源代码的问题解决
- [webpack] webpack-dev-server介绍及配置
- jQuery Mobile 导航栏
- JAVA 设计模式 备忘录模式
- 关于jquery自带动画效果的stop()问题
- 剑指Offer 变态跳台阶
- EI表达式和JSTL
- PLSQL_基础系列08_操作符标LPAD / TRUNC / DECODE / TRIM / INSTR(案例)
- C#三种判断数据库中取出的字段值是否为空(NULL) 的方法
- 基于visual Studio2013解决面试题之0604O(1)时间复杂度删除链表节点
- [UWP小白日记-9]页面跳转过度动画(二)
- Spring 数据库连接(Connection)绑定线程(Thread)的实现
- Normalize.css &; Reset
- CSS选择器、样式、盒模型
- mvn package
- iOS开发-带Placeholder的UITextView实现
- 学习Java 采取令牌的方式避免重复提交
- BZOJ1064 NOI2008假面舞会(dfs树)
- 配置Spring Boot通过@ConditionalOnProperty来控制Configuration是否生效
- Kali之——解决物理机U盘安装Kali Linux2018.1,光驱无法加载问题