public class Key implements USB {
public void work(){
System.out.println("键盘工作");
}
}
public class Mouse implements USB{
public void work(){
System.out.println("鼠标工作");
}
}
public class Computer {
public void letUSBWork(USB usb){
usb.work();
}
}
public interface USB {
public void work();
}
public class Test {
public static void main(String[] args) {
Computer com = new Computer();
Key k = new Key();
Mouse m = new Mouse();
com.letUSBWork(k);
com.letUSBWork(m);
}
}
java 小白 接口加上多态
最新推荐文章于 2021-12-25 22:41:25 发布