I was reading introduction to Java programming and it does not have a good explanation regarding this topic and it made me wonder why should someone use a private inner class in java instead of using a public one.
They both can be used only by the outer class.
Your claim
They both can be used only by the outer class.
is wrong:Note that you can actually have an instance of
A.C
in another class and refer to it asC
(including all its public declaration), but not forA.B
.From this you can understand, you should use private/public modifier for inner classes the same way you use it generally.