Thursday, March 27, 2014

OCJP practice question #5

7:40 PM

      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. 

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


Post a Comment


© 2014 DieHardTechy . All rights resevered. Designed by Diehardtechy