EqualityTest.java
class X { int p; int q; X( int m, int n ) { p = m; q = n; } boolean equals( X other ) { return p == other.p; } //(A) } class Test { public static void main( String[] args ) { X x1 = new X( 10, 100 ); // x1 and x2 //(B) X x2 = new X( 10, 10000 ); // look very different //(C) System.out.println( x1.equals( x2 ) ); // true //(D) } }
Maintained by John Loomis, last updated 30 Dec 2006