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-26  เมท็อด equals ของคลาส Complex ที่แทนของคลาส Object
public class Complex {
  private double real, imag;
  ...
  public boolean equals(Object obj) {
    if (!(obj instanceof Complex)) return false;
    Complex z = (Complex) obj;
    return real == z.real && imag == z.imag;
  }
©2009 S.Prasitjutrakul