This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why protected modifier is not allowed? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why protected modifier is not allowed?" Watch "why protected modifier is not allowed?" New topic
Author

why protected modifier is not allowed?

Anjali Vaidya
Ranch Hand

Joined: Jan 25, 2011
Posts: 40

In the following code, there is an error on line 11 saying "modifier protected not allowed here". what is the reason?
Krisztian Milesz
Greenhorn

Joined: Mar 02, 2008
Posts: 5
You cannot use the protected access modifier for top level classes.
The protected modifier means that the member can only be accessed within its own package or by a subclass of its class in another package.

At top level you can only use the public modifier or no modifier (package-private).

rakeshdec kumar
Greenhorn

Joined: Feb 17, 2011
Posts: 9
Only modifiers that applicable for Outer classes are public

<default>

abstract

final

strictfp
Anjali Vaidya
Ranch Hand

Joined: Jan 25, 2011
Posts: 40

Can you make a subclass protected if it is extending a public class? I think no, because it is restricting the access
Then when exactly can we use protected?
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3615
    
  14

You can never make a top level class protected. It makes no sense, it doesn't mean anything.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why protected modifier is not allowed?