• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Protected VS default restiction level

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can somebody please explain me why is PROTECTED considered to be more restrictive than DEFAULT?
I think it should be the other way around. Let me explain:

DEFAULT:
member visible to other classes in the same package

PROTECTED:
member visible to other classes in the same package
+
member visible to subclasses outside the package (through inheritance)

That means that in the same conditions:
"Number of classes that can access PROTECTED member" > "Number of classes that can access DEFAULT member"
by this we can say that DEFAULT restricts the access to a smaller group of classes than PROTECTED does ---> DEFAULT is being more restrictive!


What am I missing to understand then?
Thanks
 
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't think protected was considered more restrictive. I thought the order was (from least restrictive to most):

Public
Protected
Default
Private
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rui,

I agree that what you and Joe said is correct.

Protected is definitely less restrictive than default is.
 
Rui Leal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're both right. Default is in fact more restrictive than protected.
I read somewhere that stated (erroneously) that protected was more restrictive than default... damn it!
Well, that makes both of you and my intuition right

Thanks
 
Diana Sule
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
reply
    Bookmark Topic Watch Topic
  • New Topic