-1

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?

geekNava
  • 51
  • 1
  • 4

2 Answers2

4

You could use nested classes.

Link: https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html

Tacolibre
  • 110
  • 2
  • 12
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.

Vasu
  • 21,832
  • 11
  • 51
  • 67