File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Difference between Hiding, Shadowing & Obscuring" Watch "Difference between Hiding, Shadowing & Obscuring" New topic

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.
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
§ Hiding (by Class Methods)
I hope that helps.

SCJP Tipline, etc.
I agree. Here's the link:
subject: Difference between Hiding, Shadowing & Obscuring
It's not a secret anymore!