Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access modifiers for class

 
Rajiv Rai
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read in SCJP book that applying private and protected
access modifiers to a class doesn't make sense,,


Please help me to understand why it doesnt not make any sense to apply those
two modifiers to classes..

Thanks.
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For top-level classes that's true, and nto only does it not make sense, the compiler will not even allow the use of those modifiers.
Have a look at this page on access modifiers, and try to figure out why that is.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think about what it would mean if they were allowed.

For example, private. What would a private class mean? It would probably be a class that was not visible to any other class. So what use would it be? Can you think of a situation where you would want that?

This is often the best way to go about resolving any queries along the lines of "why isn't that modifier allowed here". Think about what the effect would be if it was allowed, and when you might need that. Usually it just wouldn't make sense.
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, have a look at this topic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic