public static void main(String args[]) { Float f=new Float(4.2f); Float c; Double d=new Double(4.2); float fl=4.2f; c=f; } which will return true?. Select all f.equls(d) c==f c==d c.equls(f) Ans is c==f and c.equls(f) But why equls is right too?
Rashmi Tambe
Ranch Hand
Joined: Aug 07, 2001
Posts: 418
posted
0
Hi Hades, == checks if both the references c and are pointing to same object. In this case, yes. equalsjust checks if both references are refering to same value. Now and f are pointing to same object so equals would return true as they both contain value 4.2f. In other word... equals would always return true if == returns true. vice a versa is not always true correct me if i am wrong. Rashmi