File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

QUESSION OF equls()

 
Hades Pan
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 418
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Hades Pan
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank Rashmi very much~~!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic