Java Programming - Objects and Collections - Discussion
Discussion Forum : Objects and Collections - General Questions (Q.No. 2)
2.
Which class does not override the equals() and hashCode() methods, inheriting them directly from class Object?
Answer: Option
Explanation:
java.lang.StringBuffer is the only class in the list that uses the default methods provided by class Object.
Discussion:
15 comments Page 1 of 2.
Santhosh said:
8 years ago
I didn't understand it. Can you give a clear explanation?
Ravindra Babu said:
8 years ago
Java.lang.StringBuffer is the only class that uses default methods provided by class object.
(1)
Gayudhaya said:
8 years ago
I didn't understand it can you give a clear explanation?
Anoop kumar said:
8 years ago
Please tell me, what you mean by overriding?
Vinod said:
1 decade ago
Because StringBuffer is mutable, and its primary use is for constructing strings. If you want to compare content, call StringBuffer#toString() and compare the returned value.
It is not generally useful to override hashCode() for mutable objects, since modifying such an object that is used as a key in a Hash Map could cause the stored value to be "lost".
It is not generally useful to override hashCode() for mutable objects, since modifying such an object that is used as a key in a Hash Map could cause the stored value to be "lost".
Asdf said:
1 decade ago
I think StringBuffer and StringBuilder are class use to make string immutable.
Narasimha said:
1 decade ago
I am confusing why StringBuffer and StringBuilder are not able to overriding these two methods equals and hashcode() methods. Please could you clarify the same. Thank you.
G Sunil Kumar said:
1 decade ago
Why the special behavior for StringBuffer class only?
Monika said:
1 decade ago
I think StringBuffer just uses these two methods as they are provided from Object class. The other three classes override them.
(1)
Manoj said:
1 decade ago
Please could you give full description?
Why StringBuffer class does not support direct overriding these 2 methods?
Why StringBuffer class does not support direct overriding these 2 methods?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers