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 Java in General and the fly likes Difference between protected and default. 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 » Java in General
Bookmark "Difference between protected and default." Watch "Difference between protected and default." New topic
Author

Difference between protected and default.

merlin bar
Ranch Hand

Joined: Feb 16, 2003
Posts: 54
*Only classes within the same package can see a default class.
*Protected classes can only be seen within the same package(, or subclasses of the class).
I understand the first statement. But the second statement, the part in brackets seems redundant. If the scope is package wide, then does this not also include subclasses?
If so, this means there is no difference between default and package scope.
Any clarity is appreciated.
Regards,
merlin


Regards,<br /> merlin_bar
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34


If the scope is package wide, then does this not also include subclasses?

It does indeed include subclasses in the same package, but not those in other packages. "protected" extends access to all subclasses regardless of package location.


[Jess in Action][AskingGoodQuestions]
merlin bar
Ranch Hand

Joined: Feb 16, 2003
Posts: 54
Ah, I see. Subclasses in another package - I didn't think that was possible. Thankyou for the clarification.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between protected and default.
 
Similar Threads
Constructors.
Second page of book, first question - Access modifiers
Section 6.6.7 of JLS ?
top level class access modifier woes
Protected Scope