|
Did the == operator look at the contents of the objects when the if statement executed? A good answer might be:No. It only looked at the two reference variables. They each held different references, so the == evaluated to false. | |
Two Reference Variables Pointing to One Object.Here is another example program:
When this program runs, only one object is created (by the new). Information about how to find the object is put into strA. The assignment operator in the statement
copies the information that is in strA to strB. It does not make a copy of the object! Or, saying nearly the same thing: making a copy of a reference to an object does not make a copy of the object! Since the same information is stored in strA as in strB, either variable leads to the same object. This is somewhat like giving your phone number to several people: each copy of your phone number is a reference to you, but there is only one you. The program will output: The Gingham Dog The Gingham Dog Same info in each reference variable. | |
QUESTION 14:How many objects are there in this program? How many reference variables are there? Click Here after you have answered the question |