Java接口interface
作者:互联网
package com.leo.interface_;
public interface UsbInterface {
public void start();
public void stop();
}
package com.leo.interface_;
public class Camera implements UsbInterface{
@Override
public void start() {
System.out.println("相机开始工作");
}
@Override
public void stop() {
System.out.println("相机停止工作");
}
}
package com.leo.interface_;
public class Phone implements UsbInterface{
@Override
public void start() {
System.out.println("手机开始工作");
}
@Override
public void stop() {
System.out.println("手机停止工作");
}
}
package com.leo.interface_;
public class Computer{
public void work(UsbInterface usbInterface) {
usbInterface.start();
usbInterface.stop();
}
}
package com.leo.interface_;
public interface Interface01 {
public static void main(String[] args) {
Camera camera = new Camera();
Phone phone = new Phone();
Computer computer = new Computer();
computer.work(phone);
computer.work(camera);
}
}
标签:Java,package,void,接口,leo,interface,com,public 来源: https://blog.csdn.net/qq2942713658/article/details/116333183