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:
Post a Comment