Accessing Outer class attribute from an instance of an Inner class?

You could write a getter method in the inner class, which returns n of the outer class.

As with instance methods and variables, an inner class is associated with an instance of its enclosing class and has direct access to that object's methods and fields. - Java OO You could write a getter method in the inner class, which returns n of the outer class. Method on Inner: public int getOuterN() { return n; } Then compare using this method: getOuterN()!

= that.getOuterN().

N is a public attribute of Outer, and not accessible as an attribute of that. Trying this gives a "cannot find symbol" error – rampion Nov 21 '09 at 17:33 yes, of course. Added an alternative using methods .. – miku Nov 21 '09 at 17:38 somebody copied my first answer ;) - does n!

= that. N work after all? – miku Nov 21 '09 at 17:44 I wound up going with the slightly more general public Outer parent() { return Outer.

This; } so I could access all the members I needed to. – rampion Nov 21 '09 at 20:49.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions