File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes QUESSION OF equls() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "QUESSION OF equls()" Watch "QUESSION OF equls()" New topic
Author

QUESSION OF equls()

Hades Pan
Ranch Hand

Joined: Nov 25, 2001
Posts: 106
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
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

Joined: Nov 25, 2001
Posts: 106
Thank Rashmi very much~~!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: QUESSION OF equls()
 
Similar Threads
convert double to float ?
converting float to double
equals
wrappers
formatting string %4.2f