|
If you made a Xerox© copy of a sheet of paper, you would have two sheets of paper. A good answer might be:
|
String literals
Strings are very common in programs,
so Java optimizes their use.
Usually if you need a string in your program you create it as follows.
Notice that String str = "String Literal" ;
This creates a string literal that contains the characters
For example, say that a program contained the following statements: String str1, str2; str1 = "String Literal" ; . . . . str2 = "String Literal" ;
Only one object will be created, containing the characters
This is different from this situation:
In the above situation, two objects are created, containing identical data. The compiler does not try to reuse the first object. |
QUESTION 20:How many objects are created by the following code: Click Here after you have answered the questionString msg1, msg2, msg3; msg1 = "Look Out!" ; . . . . msg2 = "Look Out!" ; . . . . msg3 = "Look Out!" ; |