I know that Java doesnt allow a top level class to be private however is there any way that the private classes are allowed apart from top level class?
Can we declare class as 'private' in java?
4.4k Views Asked by geekNava At
2
There are 2 best solutions below
0

A class is a user-defined (custom) datatype and you can't declare a class
in Java as private
, but if you do not want to expose a particular user-defined data type (class) outside of another public
class, then you can declare that as a nested/inner class (i.e., as a member of the public
class). You can refer here for details.
You could use nested classes.
Link: https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html