July 25, 2023
Given:
What is the output of the given code fragment?
#java #certificationquestion #ocp
Answer: false true true
Variables d1 and d2 are referencing objects of the wrapper type Double.
The == operator compares objects by reference, which means the expression d1==d2 evaluates to false.
However, when a primitive value is compared with an instance of a wrapper class, the instance is automatically unboxed.
Consequently, both expressions d2==d3 and d3==d1 evaluate to true.