Problem

I Wonder Why (Challenging)Did you ever wonder why Java classes are defined the way they ar...

I Wonder Why (Challenging)

Did you ever wonder why Java classes are defined the way they are? Why are certain inherited methods overridden and others not? For example, the == operator compares references, as does equals(Object o) inherited from Object. However, equals(Object o) can be, and often is, overridden. String overrides equals(Object o), but StringBuilder does not. When applied to String objects, equals(Object o) compares characters but the == operator compares references. This is not the case with StringBuilder where both == and equals(Object o) compare references.

a. Why do you think Java’s designers made this choice? Justify your answer.


b. How is this choice related to the immutability of String objects and/or the fact that the hashCode() method must assign the same value to “equal” objects. You may need to do a little research to answer this question.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 17
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT