• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question from Dan's exam.

 
sanjana narayanan
Ranch Hand
Posts: 142
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 116
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic