You need to access str from the Outer class because str is not present in the Inner class.
str is out of scope in the UseOuter class' main method.
So it looks like anonymous inner classes does not have access to the enclosing class' members when defined outside the enclosing class.
Very confusing!
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Originally posted by Barry Gaunt:
A subclass can see only the members inherited from its superclasses. Outer.str is not a member of Outer.Inner because Inner does not extend Outer.
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |