String msg1, msg2, msg3; msg1 = "Look Out!" ; . . . . msg2 = "Look Out!" ; . . . . msg3 = "Look Out!" ; A good answer might be:
Since these are identical string literals, only one object is created.
The reference variables | |
Example ProgramHere is an example program that shows this subtle difference. It would be useful to copy, paste, and run.
Here is a picture of the program (after the first four statements have run):
Like many optimizations, you almost wish they hadn't done it. It does confuse things. But real-world programs often use the same message in many places (for example "yes" and "no") and it saves space and time to have only one copy. Only rarely will you need to think about this difference.
But the difference between | |
QUESTION 21:How would the program change if the second statement were changed to:
Click Here after you have answered the question
|