shape.java

来自「Beginning Java 2, SDK 1.4 Edition Exerci」· Java 代码 · 共 21 行

JAVA
21
字号
// Chapter 6 Exercises 1 & 2

// ABSTRACT BASE CLASS FOR SHAPE.
// The move() method that  is implemented here assumes shapes are defined 
// relative to the reference point, position, so subclasses of this class
// must be defined in this way. Where this is not convenient an alternative is
// to implement a separate move() method in each derived class.

public abstract class Shape {
  protected Point position;     // Position of a shape.

// Method to move a shape:
  public void move(double xDelta, double yDelta) {
    // Move the shape by xDelta in x, and yDelta in y:
    position.x += xDelta;		
    position.y += yDelta;
  }

  public abstract void show();	// Abstract method to output a shape.
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?