9. สร้างใหม่จากเก่า

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 9-3  คลาส ColoredBall (แบบไม่มี this. super.) เพราะของแม่ก็เหมือนของลูก
import jlab.graphics.DWindow;
public class ColoredBall extends Ball {
  private int color;
  public ColoredBall(double r, double x, double y) {
    this(r, x, y, DWindow.BLACK);
  }
  public ColoredBall(double r, double x, double y, int color) {
    super(r, x, y);
    this.color = color;
  }
  public void setColor(int c) {
    color = c;
  }
  public int getColor() {
    return color;
  }
  public void draw(DWindow w) {
    w.fillEllipse(color, x, y, 2*r, 2*r);
  }
}
©2009 S.Prasitjutrakul