jQuery in Action, 3rd edition
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark " class variable shadowing " Watch " class variable shadowing " New topic

class variable shadowing

Keith Lockey

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

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.
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
I agree. Here's the link: http://aspose.com/file-tools
subject: class variable shadowing
It's not a secret anymore!