集册 Java实例教程 演示将接口类型用作变量类型

演示将接口类型用作变量类型

欢马劈雪     最近更新时间:2020-01-02 10:19:05

504
演示将接口类型用作变量类型

interface Shape {

  void draw();

}/** from NowJava.com - 时  代  Java**/


class Main {

  // Interface type to define instance variable

  private Shape myShape;


  // Interface type to define parameter type for a constructor

  public Main(Shape a) {

    this.myShape = a;

  }


  // Interface type to define return type of a method

  public Shape getSwimmable() {
  /* 
  *来 自
   NowJava.com - 时  代  Java
  */

    return this.myShape;

  }


  // Interface type to define parameter type for a method

  public void setSwimmable(Shape a) {

    this.myShape = a;

  }


  public 
展开阅读全文