dennisac
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 }

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

分类:

技术点:

相关文章:

  • 2021-09-19
  • 2021-07-13
  • 2021-06-09
  • 2021-08-13
  • 2022-01-23
  • 2021-10-25
  • 2022-01-21
  • 2021-06-28
猜你喜欢
  • 2021-05-02
  • 2021-10-10
  • 2021-05-16
  • 2021-12-05
  • 2021-12-10
  • 2021-12-18
相关资源
相似解决方案