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 小白 接口加上多态
最新推荐文章于 2025-04-17 01:33:38 发布
由于未提供博客具体内容,无法生成包含关键信息的摘要。

422

被折叠的 条评论
为什么被折叠?



