Your statement They both can be used only by the outer class. wrong:
public class A { private class B {} public class C {} public C getC() { return new C(); } public B getB() { return new B(); } } public class Tryout { public static void main(String[] args) { A a = new A(); AB b = a.getB();
Please note: in fact, you can have an AC instance in another class and refer to it as C (including all its public declarations), but not AB .
From this you can understand, you should use a private / public modifier for inner classes the same way you use it.
amit
source share