Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Protected Access Specifier

 
kedar parundekar
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why "Protected" access specifier is not allowed to Top Level classes?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at it this way: Suppose you could make a top level class "protected". What would that mean? Why would that be useful?
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jesper Young:
Look at it this way: Suppose you could make a top level class "protected". What would that mean?


It would mean your code is protected for more secure programming, right?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49451
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would that mean?

I have never tried it, but I think it would mean that there is no access to subclasses outside the superclass' package. Anybody wish to try it? I don't.

CR
 
kedar parundekar
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jesper Young:
Look at it this way: Suppose you could make a top level class "protected". What would that mean? Why would that be useful?


I agree with you answer.
But my another query is -> If I want to use this protected class in same package only. why it is not useful?
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by kedar parundekar:

If I want to use this protected class in same package only. why it is not useful?


In your hypothetical change to Java, what would be the difference between these two top-level classes?

[ May 17, 2006: Message edited by: Jeff Albertson ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic