我的爱情你的名字吧 关注:86贴子:14,992
  • 2回复贴,共1


1楼2019-11-13 10:55回复

    //USB接口定义
    public interface USB{
    public void work();
    public void insert();
    }
    //MP3 类实现了 USB接口
    public class Mp3 implements USB{
    private String brand;
    public Mp3(){
    brand="unknown";
    }
    public Mp3(String brand){
    this.brand=brand;
    }
    public void work(){
    System.out.println(brand+"mp3 is working...");
    }
    public void insert(){
    System.out.println(brand+" mp3 is inserting...");
    }
    }
    //printer 类实现了USB接口
    public class Printer implements USB{
    private String brand;
    public printer(){
    brand="unknown";
    }
    public printer (String brand){
    this.brand=brand;
    }
    public void work(){
    Sysem.out.println(brand+"Pinter is working...");
    }
    public void insert(){
    Sysem.out.println(brand+"Pinter is inerting.."
    }
    }


    2楼2019-11-13 11:23
    收起回复
      package seventeen;
      interface USB{
      public void work();
      public void insert();
      }
      class Mp3 implements USB{
      private String brand;
      public Mp3() {
      brand="unknown";
      }
      public Mp3(String brand) {
      this.brand=brand;
      }
      public void work() {
      System.out.println(brand+"mp3 is working...");
      }
      public void insert() {
      System.out.println(brand+"mp3 is inserting...");
      }
      }
      class Printer implements USB{
      private String brand;
      public Printer() {
      brand="unknown";
      }
      public Printer(String brand) {
      this.brand=brand;
      }
      public void work() {
      System.out.println(brand+"Printer is working...");
      }
      public void insert() {
      System.out.println(brand+"Printer is inserting...");
      }
      }
      class computer{
      void useUSB(USB usb) {
      usb.work();
      usb.insert();
      }
      }
      public class Test3 { public static void main(String[] args) {
      // TODO Auto-generated method stub
      Mp3 mp3 = new Mp3("philipse");
      Printer printer = new Printer("hp");
      computer IBM = new computer();
      IBM.useUSB(mp3);
      IBM.useUSB(printer);
      }}


      3楼2019-11-13 12:46
      回复