Yes, it is possible to have a private class, but only as an inner class of another class:
public class Outer { private class Inner {} }
This is usually useful if you want to encapsulate some logic inside the class (external), but to implement it you need a more structured / OO code. I used this template in the past when I needed a container class to process some information in a class method, but the container class does not make sense outside of this logic. Creating a container class of a private inner class means that its use is localized in the outer class that uses it.
It is worth noting that with this structure, the inner class has access to the private members of the outer class, but not vice versa.
adrianbanks
source share