*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Shadowing Variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Shadowing Variable" Watch "Shadowing Variable" New topic
Author

Shadowing Variable

Esha Naidu
Greenhorn

Joined: May 02, 2007
Posts: 2
Hi..
Can any one Help me out in clearing the concept of shadowing variable..
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

If I remember, it could be like a local variable which has the same name as an instance variable.

"name" in doSomething is shadowing the instance "name".


[My Blog]
All roads lead to JavaRanch
Manfred Klug
Ranch Hand

Joined: Jun 04, 2007
Posts: 377
Another example is shadowing instance variables of a parent class.
Esha Naidu
Greenhorn

Joined: May 02, 2007
Posts: 2
Hi
Thanku for the replies
Below is code from K&B book
i thought the answer could be 28 99 420 28
but the answer is 28 99 420 99 how it is taking 99 instead of 28 can anyone expalin me clearly..
how the shadowing variable concept is involved here.
Thanks in advance



kathir vel
Ranch Hand

Joined: Jul 03, 2007
Posts: 92
changeIt() is passing the refference of Bar object.So its(passed obect's state) state is changed to 99.Then ,new bar object is assigend to this local refferece variable.Making changes (assigning 420)in this new bar object's state won't affect the called refference Object's state.So after completion of changeIt() method ,Bar object is barNum value is 99.
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Esha NS, see this:
http://www.javaranch.com/name.jsp




and change your user name please.


using the code tag on code that hasn't any indentations is pretty useless.

Same code indented:



Yours,
Bu.


all events occur in real time
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Shadowing Variable
 
Similar Threads
Final keyword???
Shadow variables
constructor's call
Overriding Khalid example
Inheriting a protected member