The answer is that the following are correct:Consider the following lines of code:
Integer i = new Integer(42);
Long ln = new Long(42);
Double d = new Double(42.0);
Which of the following options are valid code fragments?
i == ln;
ln == d;
i.equals(d);
d.equals(ln);
ln.equals(42);
i.equals(d);
d.equals(ln);
ln.equals(42);
I wonder why "i.equals(d);" is correct?
i == d
can never happen because i and d are references to different classes of objects that have no relation between themselves.
But...I think the answer is correct because equals() can be overridden.
The same thing goes for "d.equals(ln)" I think.
Am I correct?