You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.1 KiB
49 lines
1.1 KiB
interface USB {//规定usb的规范
|
|
void plugln();
|
|
void work();
|
|
}
|
|
|
|
class Mouse implements USB {//implement意思是遵守规范
|
|
@Override
|
|
public void plugln(){
|
|
System.out.println("鼠标已接入USB口");
|
|
}
|
|
|
|
@Override
|
|
public void work(){
|
|
System.out.println("鼠标:移动光标,点击左右键");
|
|
}
|
|
}
|
|
|
|
class Keyboard implements USB{
|
|
@Override
|
|
public void plugln(){
|
|
System.out.println("键盘已插入USB口");
|
|
}
|
|
|
|
@Override
|
|
public void work(){
|
|
System.out.println("键盘:可以打字输入");
|
|
}
|
|
}
|
|
|
|
class Conputer{
|
|
public void useUSB(USB usb){
|
|
System.out.println("电脑检测到新设备");
|
|
usb.plugln();
|
|
usb.work();
|
|
System.out.println();
|
|
}
|
|
}
|
|
|
|
public class USBTest {
|
|
public static void main(String[] args) {
|
|
Computer computer = new Conputer();
|
|
|
|
USB mouse=new Mouse();
|
|
USB keyborad=new Keyboard();
|
|
|
|
computer.useUSB(mouse);
|
|
computer.useUSB(keyboard);
|
|
}
|
|
}
|