java USB标准

View Code
 1 interface USB{
2 public void start();
3 public void stop();
4 }
5 class Computer{
6 public static void plugin(USB usb){
7 usb.start();
8 System.out.println("=========USB device is working======");
9 usb.stop();
10 }
11 };
12 class Flash implements USB{
13 public void start(){
14 System.out.println("U-disk starts working...");
15 }
16 public void stop(){
17 System.out.println("U-disk stops working...");
18 }
19 };
20 class Print implements USB{
21 public void start(){
22 System.out.println("Printer starts working...");
23 }
24 public void stop(){
25 System.out.println("Printer stops working...");
26 }
27 }
28
29 public class InterfaceCaseDemo02 {
30 public static void main(String args[]){
31 Computer.plugin(new Flash());
32 Computer.plugin(new Print());
33 }
34 }

可以看出,计算机关心的只是接口,对于具体设备,毫不关心。

原文地址:https://www.cnblogs.com/dennisac/p/2382598.html