• Advertisement
Sign in to follow this  

[java] Quick and Easy Question

This topic is 3675 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I can't seem to get this to stick in my head but: if I create a graphics object ("myGraphics") and then create another Graphics Object ("myOtherGraphics") and set myOtherGraphics = myGraphics.getGraphics(); then, when I make changes to myGraphics, do the same changes happen to myOtherGraphics? or the other way around? in other words, are they referencing the same object. and if not, even though they aren't referencing the same object, does making changes to one, change the other? sorry if this is bit elementary. :)

Share this post


Link to post
Share on other sites
Advertisement

Graphics myGraphics = new Graphics();
Graphics myOtherGraphics = new Graphics();

myGraphics ---------------> Instance #1

myOtherGraphics ----------> Instance #2


myOtherGraphics = myGraphics;

myGraphics --------+------> Instance #1
|
myOtherGraphics ---+ Instance #2

// Instance #2 is garbage collected, since nothing is pointing at it anymore

Quote:
in other words, are they referencing the same object


Yes.

Quote:
myOtherGraphics = myGraphics.getGraphics();


Why myGraphics.getGraphics()? Why not myOtherGraphics = myGraphics; ?

getGraphics() could be returning anything, in which case what they point to depends on how getGraphics is implemented.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement