This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question from Dan's exam. 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 "Question from Dan Watch "Question from Dan New topic
Author

Question from Dan's exam.

sanjana narayanan
Ranch Hand

Joined: Nov 25, 2003
Posts: 142
Hi,
This is a simple question from Dan's exam.
Boolean b1 = new Boolean(true);
Boolean b2 = new Boolean(true);
Boolean b3 = new Boolean("TrUe");
Boolean b4 = new Boolean("tRuE");
System.out.print((b1==b2) + ","); //1
System.out.print((b1.booleanValue()==b2.booleanValue()) + ",");//2
System.out.println(b3.equals(b4));
Ths ans given is : false,true,true
My doubt is in the line #2. It seems to be v..simple but i am getting confused. When ohjects are not equal(line #1), how can the value be the equal in (line#2) .
Pl. explain this.
-Sanjana
Vishy Karl
Ranch Hand

Joined: Sep 08, 2003
Posts: 116
Hi There,
It is simple
In line#1 u r comparing the objects themselves , since they r stored at diff. locations in memory it returns false , while in lines 2 and 3 you are comparing the values stored at these memory locations which returns true.
Hope it makes sense,
Good luck;


"The man who can drive himself further once the effort gets painful is the man who will win." <br />Roger Bannister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question from Dan's exam.
 
Similar Threads
One more on wrapper classes from Dan's mock exam..
Boolean class
equals()
Dan's Question : Fundamental Classes
Boxing and unboxing in Java 5