Possible Duplicate:
Returning false from Equals methods without Overriding
One of my colleague asked me a question today as mentioned below
Write TestEquals class(custom or user defined class) so that the below s.o.p in the code prints false.
public class Puzzle3 {
public static void main(String[] args) {
TestEquals testEquals = new TestEquals();
System.out.println(testEquals.equals(testEquals));
}
}
Note: You cannot override equals method.
I thought a lot but couldn’t find the solution without overriding equals.Does anybody have any idea how it can be done?
use
To override equals you need the input parameter to be of type object so the above code snippet theorectially is not overriding equals from the object method