Java面向对象接口的使用
package com.howie.pol;
//定义一个接口,里面有两个方法,即时规范,必须继承
interface USB{
void Start();
void Stop();
}
class Pc {
public static void work(USB usb) {
usb.Start();
System.out.println("working");
usb.Stop();
}
}
class USBDisk implements USB{
@Override
public void Start() {
System.out.println("USBDisk Working");
}
@Override
public void Stop() {
System.out.println("USBDisk Stop Working");
}
}
class Printer implements USB{
@Override
public void Start() {
System.out.println("Printer Working");
}
@Override
public void Stop() {
System.out.println("Printer Stop Working");
}
}
public class InterDemo01 {
public static void main(String[] args) {
Pc.work(new USBDisk());
Pc.work(new Printer());
}
}