public class EqualsMethod2{ public static void main( String[] args){ Value v1 = new Value(); Value v2 = new Value(); v1.i = v2.i = 100; // *** System.out.println(v1.equals(v2)); } }
The answer is false. Why is it false? I didn?t understand it. In my opinion, since equals tests the contents of the object datamember i, I understood that in line // *** v2.i receives 100, v1.i receives the memory address of v1.i, and so it?s false. Is my conclusion correct? My doubt is about the difference between == and equals. I'm reading Thinking in Java and as I got to this part this doubt appear to me. Any suggestions?