import tester.*; class ExamplesSame { public ExamplesSame() {} A test1 = new A(); A test2 = new B(); // make sure our tester knows the difference between these two objects public boolean testSameTester(Tester t) { return t.checkFail(test1, test2) && t.checkFail(test2, test1); } // check if the comparison works in once direction public boolean testSame12(Tester t) { return t.checkExpect(test1.same(test2), false, "comparing test1 and test2"); } // check if the comparison works in the other direction as well public boolean testSame21(Tester t) { return t.checkExpect(test2.same(test1), false, "comparing test2 and test1"); } } class A { int n1; public A(){ n1 = 4; } public boolean same(Object o) { if (!(o instanceof A)) { return false; } else { A rhs = (A) o; return this.n1 == rhs.n1; } } } class B extends A { int n2; public B(){ super(); n2 = 8; } public boolean same(Object o) { if (!(o instanceof B)) { return false; } else { B rhs = (B)o; return this.n1 == rhs.n1 && this.n2 == rhs.n2; } } } /* Tester Results ExamplesSame: --------------- ... new ExamplesSame:1( this.test1 = new A:2( this.n1 = 4) this.test2 = new B:3( this.n1 = 4 this.n2 = 8)) --------------- Found 3 test methods .... Ran 4 tests. 1 test failed. Test results: -------------- Error in test number 3 comparing test1 and test2 tester.ErrorReport: Error trace: at ExamplesSame.testSame12(TestSame.java:18) actual: true expected: false --- END OF TEST RESULTS --- */