package com.leo.interface_; public interface UsbInterface { public void start(); public void stop(); }
package com.leo.interface_; public class Camera implements UsbInterface{ @Override public void start() { System.out.println("相机开始工作"); } @Override public void stop() { System.out.println("相机停止工作"); } }
package com.leo.interface_; public class Phone implements UsbInterface{ @Override public void start() { System.out.println("手机开始工作"); } @Override public void stop() { System.out.println("手机停止工作"); } }
package com.leo.interface_; public class Computer{ public void work(UsbInterface usbInterface) { usbInterface.start(); usbInterface.stop(); } }
package com.leo.interface_; public interface Interface01 { public static void main(String[] args) { Camera camera = new Camera(); Phone phone = new Phone(); Computer computer = new Computer(); computer.work(phone); computer.work(camera); } }