Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 94

Given:

and the code fragment:

What is the result?

    Correct Answer: D

    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.

Discussion
Tarik2190Option: A

true:false. Tested Since it is not implementing equals, it inherits the Object's equals method, which is just == tested

asdfjhfgjuaDCVOption: D

D is the answer

steefaandOption: D

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)