1 interface USB 2 { 3 public void open(); 4 public void close(); 5 } 6 7 class Upan implements USB 8 { 9 public void open() 10 { 11 System.out.println("Upan open"); 12 } 13 public void close() 14 { 15 System.out.println("Upan close"); 16 } 17 } 18 19 class USBMouse implements USB 20 { 21 public void open() 22 { 23 System.out.println("USBMouse open"); 24 } 25 public void close() 26 { 27 System.out.println("USBMouse close"); 28 } 29 } 30 31 class BookPC 32 { 33 public static void main(String[] args) 34 { 35 useUSB(new Upan()); 36 useUSB(new USBMouse()); 37 } 38 public static void useUSB(USB u) 39 { 40 u.open(); 41 u.close(); 42 } 43 }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/11899.html