| Author |
Variables in different classes that reference the same object?
|
Michael Bruesch
Ranch Hand
Joined: Sep 23, 2001
Posts: 158
|
|
Take the following: Are listA and listB now pointing to the same List object even though they're in different classes? And say a method is called in class A that changes listA, then a method is called in class B that accesses listB, will it be changed too then? If that is true, my life will be much easier. It's a very basic question I know, but I never thought about what if the reference variables were in different classes. I can explain my particular situation as to why I ask this question if you need further details to answer the question. Thanks!
|
Michael J Bruesch<br /><i>I code, therefore I am.</i>
|
 |
Michael Ernest
High Plains Drifter
Sheriff
Joined: Oct 25, 2000
Posts: 7292
|
|
This may seem like a simple question, but there's an important revelation behind this code: there's one object in memory and it's been "mapped" by two different objects (assuming there's One instantiation of each). Changes made to the object through one reference of course chaneg what the other reference sees. If you've ever wonder how one object can "require" the existence of another before it may be constructed, well, this is it! ------------------ Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
|
Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
|
 |
Michael Bruesch
Ranch Hand
Joined: Sep 23, 2001
Posts: 158
|
|
Thanks Michael, I feel better about asking the question then. ------------------ Michael J Bruesch Codito, ergo sum... I code, therefore I am. http://www.geocities.com/mjbruesch
|
 |
 |
|
|
subject: Variables in different classes that reference the same object?
|
|
|