aspose file tools*
The moose likes Java in General and the fly likes Shadow variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Shadow variables" Watch "Shadow variables" New topic
Author

Shadow variables

Sharan Ashok Vasandani
Greenhorn

Joined: Jul 15, 2010
Posts: 6
Hi,

Is shadowing of variables from Super Class in Sub class a good practice?
Is there a situation where it is a must and cannot be avoided?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19781
    
  20

Sharan Ashok Vasandani wrote:Is shadowing of variables from Super Class in Sub class a good practice?

It adds possible ambiguity. I'd prevent it if possible - and as far as I know it's always possible; just rename the variable.

Is there a situation where it is a must and cannot be avoided?

Since there is virtually no limit on the allowed variable names it's almost always possible to avoid it, just by renaming it.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Sharan Ashok Vasandani
Greenhorn

Joined: Jul 15, 2010
Posts: 6
is variable shadowing a best practice or not?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19781
    
  20

If I say I'd prevent it if possible, does that sound like it's a good thing?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Shadow variables