String reversed = last + first; A good answer might be:No. It uses data in last and in first to construct a new object. The other objects are not altered. |
Strings are ImmutableJava was designed after programmers had about 15 years of experience with object oriented programming. One of the lessons learned in those years is that in robust code objects are seldom altered after they are constructed. So, for many Java classes objects cannot be altered after construction. The class String is one of those. String objects are immutable. This means that after construction, they cannot be altered. Once a String object has been constructed, the characters it contains will always be the same. None of its methods will change those characters, and there is no other way to change them. The characters can be used for various purposes (such as in constructing new String objects), and can be inspected. But never altered. |
QUESTION 10:Here is a line of the documentation for the String class. Now examine the following code:public String trim(); String userData = " 745 "; String fixed; fixed = userData.trim(); Has the trim() method been used correctly? How many objects have been created? Click Here after you have answered the question |