集册 Java实例教程 扩展类的功能

扩展类的功能

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

387
使用extends关键字,后跟您要扩展的类的名称。
//n o w j a v a . c o m - 时  代  Java 提供

class WoodenStick extends Stick {


  private static final String material = "WOOD";

  private int lie;

  private int flex;


  public WoodenStick(int length, boolean isCurved) {

    super(length, isCurved, material);

  }


  public WoodenStick(int length, boolean isCurved, int lie, int flex) {

    super(length, isCurved, material);

    this.lie = lie;

    this.flex = flex;

  }


  /**

   * @return the lie

   */

  public int getLie() {

    return lie;/*from nowjava.com - 时  代  Java*/

  }


  /**

   * @param lie

   *          the lie to set

   */

  public void setLie(int lie) {

    this.lie = lie;

  }


  /**

   * @return the flex

   */

  public int getFlex() {

    return flex;

  }


  /**

   * @param flex

   *          the flex to set

   */

  public void setFlex(int flex) {

    this.flex = flex;

  }

}


class Stick {


  private int length;

  private boolean curved;

  private String material;


  public Stick(int length, boolean curved, String material) {

    this.length = length;

    this.curved = curved;

    this.material = material;

  }


  /**

   * @return the length

   */

  public int getLength() {

    return length;

  }


  /**

   * @param length

   *          the length to set

   */

  public void setLength(int length) {

    this.length = length;

  }


  /**

   * @return the curved

   */

  public boolean isCurved() {

    return curved;

  }


  /**

   * @param curved

   *          the curved to set

   */

  public 
展开阅读全文