This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 14074
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
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: 38033
    
  22
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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Protected Access Specifier
 
Similar Threads
Protected Access Specifier
Protected Class
doubt in protected access specifier
A small doubt
java.lang.object