This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread 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


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: 3983
    
  18

You can never make a top level class protected. It makes no sense, it doesn't mean anything.


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
 
Have you checked out Aspose?
 
subject: why protected modifier is not allowed?
 
jQuery in Action, 3rd edition