How to access private data member outside the class?

I am trying to access the private data member of inner class outside the outer class.

Please help me?

Jon Skeet
people
quotationmark

You don't - that's the whole point of it being private.

The inner class can expose the data via a property, of course:

public class Outer {
    public class Inner {
        private final String name;

        public Inner(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }
    }
}

public class Other {
    public void foo() {
        Outer outer = new Outer();
        Outer.Inner inner = outer.new Inner("Foo");
        // Can't access inner.name here...
        System.out.println(inner.getName()); // But can call getName
    }
}

... but if the inner class wants to keep it private, then you shouldn't try to access it.

people

See more on this question at Stackoverflow