posted 15 years ago
There is an equals() method which compares two Teste objects by checking if their member variable x contains the same value. Then you call equals() to compare two Teste objects which both have x = 3. Ofcourse the result will be true.
You are simply calling the equals() method, which works just like any other method. There is no magic involved with hash codes here.
Hash codes are used by certain collection classes, such as HashSet and HashMap. If you would want to put Teste objects in a HashSet, or use Teste objects as keys in a HashMap, then class Teste would need to implement the hashCode() method so that two Teste objects which are equal have the same hash code. If class Teste does not have a correct hashCode() method, then you will get strange results when putting Teste objects in a hash code based collection.