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-25  ตัวอย่างสาธิตข้อผิดพลาดของ equals ในรหัสที่ 9-24
  Complex z1 = new Complex(1,1);
  Complex z2 = new Complex(1,1);
  Object  z3 = z2;
  System.out.println(z1.equals(z2));  // equals ของ Complex ได้ true  
  System.out.println(z2.equals(z3));  // equals ของ Object  ได้ true
  System.out.println(z1.equals(z3));  // equals ของ Object  ได้ false
©2009 S.Prasitjutrakul