Page 1 of 1

About Question enthuware.ocajp.i.v8.2.1104 :

Posted: Mon Dec 19, 2016 12:24 am
by eddie3
The answer to this question seems to be in contradiction with a a previous question from Ethuware (ocajp.i.v8.2,1369). In that question,

Code: Select all

Integer i1=1;
Byte b1 = 1;
Long g1= 1L;
The answer states that output to

Code: Select all

i1.equals(g1)
and

Code: Select all

i1.equals(b1)
are both false. And the explanation says that
The equals method of all wrapper classes first checks if the two objects are of the same class or not. If not, they immediately return false.
If this is the case, in this question,

Code: Select all

Integer i = new Integer(42);
Long ln = new Long(42);
Double d = new Double (42.0);
shouldn't

Code: Select all

i.equals(d);
or

Code: Select all

d.equals(ln)
both return false? Because they are all pointing to objects of different data types?

Re: About Question enthuware.ocajp.i.v8.2.1104 :

Posted: Mon Dec 19, 2016 2:51 am
by admin
Yes, both will return false. But they are valid code fragments, which is what the question is asking. It is not saying that they will return true.
I have updated the problem statement to make it clear.

thank you for your feedback!
Paul.