aspose file tools*
The moose likes Beginning Java and the fly likes  class variable shadowing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark " class variable shadowing " Watch " class variable shadowing " New topic
Author

class variable shadowing

Keith Lockey
Greenhorn

Joined: Jan 18, 2003
Posts: 20

don't understand the purpose of class variable shadowing?? What other types of shadowing are there. Can there be methods shadowing as well??
Thomas Thomas
Greenhorn

Joined: Jun 17, 2003
Posts: 28
I think if u view it from an object oriented perspective rather than variables and methods. The best way to manipulate variables is through method interfaces. Thats what encapsulation is all about. In java methods matching in signature r overrided not shadowed.
I hope i was answering your question.
Thanks
Thomas
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
This can lead you into very confusing and potentially buggy places. Say you have a bunch of methods on sh and sh2 that reference i.
sh thing1 = new sh();
sh2 thing2 = new sh2();
thing2.methodOnSh(); // this will use the i on sh
thing2.methodOnSh2(); // this wlil use the i on sh2
Confused? Then the short answer is Don't Do That! (Seen Terminater 3 yet?) Overload and override methods for good OO fun, but I've never had a reason to shadow variables. Anybody else?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
Don't get me started about those stupid light bulbs.
 
subject: class variable shadowing