Given:
and the code fragment:What is the result?
Given:
and the code fragment:What is the result?
In this case, the Product class does not override the equals() method from the Object class. Therefore, the default behavior of equals() is to compare memory addresses rather than the contents of the objects. In the provided code, p1 and p2 reference the same object, so p1.equals(p2) returns true. However, p3 is a different object, even though it has the same pname value. Hence, p1.equals(p3) returns false. As a result, the output will be true false.
true:false. Tested Since it is not implementing equals, it inherits the Object's equals method, which is just == tested
D is the answer
D is true. Class doesnt implement equals so equals compares if references are pointing to the same object which is case for p1 and p2, but not p3. P3 is different object in memory (although it contains same value for pname)