publicclassUSBTest{publicstaticvoidmain(String[] args){Computer com =newComputer();Flash flash =newFlash();
com.transferDate(flash);}}classComputer{publicvoidtransferDate(USB usb){//USB usb = new Flash();
usb.start();System.out.println("具体参数的细节");
usb.stop();}}interfaceUSB{// 定义为常量:定义了长宽 最大最小的传输速度voidstart();voidstop();}classFlashimplementsUSB{@Overridepublicvoidstart(){System.out.println("U盘开始工作");}@Overridepublicvoidstop(){// TODO Auto-generated method stubSystem.out.println("U盘结束工作");}}classPrinterimplementsUSB{@Overridepublicvoidstart(){System.out.println("打印机开始工作");}@Overridepublicvoidstop(){System.out.println("打印机结束工作");}}
接口的使用接口的使用上同样满足多态接口:实际上定义了一种规范开发中,体会面向接口编程public class USBTest {public static void main(String[] args) { Computer com = new Computer(); Flash flash = new Flash(); com.transferDate(flash); }}class Computer{ public void transferDate(U