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-27  เมท็อด equal และ tostring ที่ไม่ได้ไปแทนของคลาส Object
public class Complex {
  ...
  public boolean equal(Object obj) {
    if (!(obj instanceof Complex)) return false;
    Complex z = (Complex) obj;
    return real == z.real && imag == z.imag;
  }
  public String tostring() {
    return "(" + real + ", " + imag + "i)";
  }
©2009 S.Prasitjutrakul