本帖最后由 廉伟杰 于 2014-1-22 16:06 编辑
- interface IUsb//定义一种规范
- {
- void use();
- }
- class MouseUsbImpl implements IUsb
- {
- public void use()
- {
- System.out.println("使用USB鼠标");
- }
- }
- class PrintUsbImpl implements IUsb
- {
- public void use()
- {
- System.out.println("使用USB打印机");
- }
- }
- class Computer
- {
- public void run(IUsb a)//这点体现了多态的方便
- {
- a.use();
- }
- }
- class Demo2
- {
- public static void main(String[] args)
- {
- IUsb mouse = new MouseUsbImpl();//多态
- IUsb printl = new PrintUsbImpl();
- Computer c = new Computer();
- c.run(mouse);
- c.run(printl);
- System.out.println("Hello World!");
- }
- }
复制代码 Demo2.java:21: 错误: 非法字符: \65289
public void run(IUsb a)//这点体现了多态的方便
^
1 个错误
|