aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Difference between Hiding, Shadowing & Obscuring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Difference between Hiding, Shadowing & Obscuring" Watch "Difference between Hiding, Shadowing & Obscuring" New topic
Author

Difference between Hiding, Shadowing & Obscuring

Sudhakar Krishnamurthy
Ranch Hand

Joined: Jun 02, 2003
Posts: 76
Can anyone explain how exactly Hiding, Shadowing & Obscuring are different?
I used to think they are all the same.
TIA
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
There's lots of good info on this in the JLS, but let me try to explain best I can.
Hiding deals with inheritance of classes. A variable or method in a subclass can hide a variable or method in the superclass. Here's an example:

Shadowing is really the same notion and is, in my opinion, only subtly different. With shadowing, inheritance is not involved. Rather, some variable, which is currently in scope, is "shadowed" by another variable with the same name. This shadowing causes the original variable to be inaccessible (by a simple name) until the new variable goes out of scope. Here's another example:

Obscuring isn't seen very often. Obscuring really occurs when no differentation can be made between the name of a variable, a type, or a package. In general, if you follow proper naming conventions, you'll rarely run into such a case.
Here are some points of interest in the JLS that will give you more info on these three things:
§6.3.1 Shadowing Declarations
§6.3.2 Obscured Declarations
§8.3 Field Declarations
§8.4.6.2 Hiding (by Class Methods)
I hope that helps.


SCJP Tipline, etc.
 
Consider Paul's rocket mass heater.
 
subject: Difference between Hiding, Shadowing & Obscuring