Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between protected and default.

 
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
Marshal
Pie
Posts: 24208
35
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic