• Post Reply Bookmark Topic Watch Topic
  • New Topic

Access modifier private  RSS feed

 
Urs Waefler
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code: It does not compile because the access modifier private is not allowed. I do not have an explanation. Why is it not allowed to make a class private? What is the problem?
 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem? It's pointless. What code could access a private class? (Hint: the answer isn't "Nothing".)
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Paul said, a top-level private class is pointless.  A nested private class, however, is not only legal but it's also useful in certain design contexts, where you need to separate certain concerns but still keep the scope of those concerns to a minimum and make it available only to the enclosing class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!