Tech Me More

To quench our thirst of sharing knowledge about our day to day experience & solution to techincal problems we face in our projects.

Advertise with us !
Send us an email at diehardtechy@gmail.com

Thursday, March 27, 2014

OCJP practice question #5

      What will be the output of following java program ?? 


Solution: Option E is correct. StringBuffer class doesn’t override the equals() method, so two different StringBuffer objects with same value will not be equal according to the
equals() method. 

On the other hand,equals() method has been overridden in String class so that two different String objects with the same value will be considered equal according to the equals() method. 

Note:
As equals() method compares object by default, but by overriding we can change its behavior to compare by value.

No comments: