• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

shadowing an object

 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
from P-218 kathy sierra
shadowing a object.........


The preceding code prints out this:
f.myBar.barNum is 28
myBar.barNum in changeIt is 99
myBar.barNum in changeIt is now 420
f.myBar.barNum after changeIt is 99


can anybody tell me how the output comes i am not able to understand this.....................
 
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
take following points into consideration
1. assigning one variable to another variable means that we are copying the bits present in one variable into another variable

we will first see how the objects are their reference variables are

the reference variables hold the bits which represent the memory of the object at which it is stored (unlike primitives where direct value (those are also bits )are copied )
so even when we assign one reference variable to some another reference variable then the bits that represent the memory at which object resides are copied (hence the object is not copied and the object is the same and both the reference variables refer to the same object now )

read the comments in the program now
start the flow from main method


was a little complicated
I hope I have explained well but if you still don't have understood
feel free to ask , I will write full explanation then
but first go through the explanation in the book once again
happy learning
 
Straws are for suckers. Now suck on this tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic