Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Difference between protected and default.  RSS feed

 
merlin bar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
*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
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
merlin bar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I see. Subclasses in another package - I didn't think that was possible. Thankyou for the clarification.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!