aspose file tools*
The moose likes Beginning Java and the fly likes Protected  Access Specifier Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Protected  Access Specifier" Watch "Protected  Access Specifier" New topic
Author

Protected Access Specifier

kedar parundekar
Ranch Hand

Joined: May 10, 2006
Posts: 40
Why "Protected" access specifier is not allowed to Top Level classes?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14266
    
  21

Look at it this way: Suppose you could make a top level class "protected". What would that mean? Why would that be useful?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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

Joined: Oct 13, 2005
Posts: 39393
    
  28
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

Joined: May 10, 2006
Posts: 40
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

Joined: Sep 16, 2005
Posts: 1780
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Protected Access Specifier