This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Inner classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inner classes" Watch "Inner classes" New topic

Inner classes

Sam Samson
Ranch Hand

Joined: Oct 08, 2011
Posts: 63


This will print out "inner". But why? Why not "outer"? Will the inner class always be chosen over the outer?
If I comment the inner class, the outer will be chosen.
dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
In much the same way that a method local variable can shadow a class level variable with the same name, the class A is shadowed by the class TestInners.A.
Sam Samson
Ranch Hand

Joined: Oct 08, 2011
Posts: 63

Ah, ok, that make sense, thanks :-)

But I couldn't find examples for 'shadowing a class' via Google. Are you sure that this is called shadowing?
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3028
Yes. Shadowing a class is a relatively rare thing - but the concept of shadowing in Java can apply to most anything with a name, including variables, methods, and classes.
Have you checked out Aspose?
subject: Inner classes
It's not a secret anymore!