interface IUSB {
public boolean check();
public void work();
}
class Computer {
public void plugin(IUSB usb){// 电脑上使用USB设备---??什么格式
if(usb.check()){
usb.work();
} else {
System.out.println("硬件设备出现问题,无法使用");
}
}
}
class Keyboard implements IUSB {
public boolean check(){
return true;
}
public void work(){
System.out.println("打开电脑在线学习 ,输入www.baidu.com");
}
}
class Print implements IUSB {
public boolean check(){// 覆写抽象方法
return false;
}
public void work(){
System.out.println("打印魔乐科技,帅气");
}
}
public class HelloWorld {
public static void main(String args[]){
Computer computer = new Computer();
computer.plugin(new Keyboard());// 插入键盘设备
computer.plugin(new Print());//
}
}
标签:void,work,IUSB,public,标准,9.9,接口定义,class,check
From: https://www.cnblogs.com/pansidong/p/17471554.html