• 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

The notion of a "protected class"

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does it make sense to make all the members of a class protected ? If yes, then why go through the trouble of typing protected many times. Why not make the whole class protected, ie protected class MyClass ?
I know that java does not allow protected and private here. I understand why private makes no sense because that class will not be accessible at all and even its main() cant be run. Its the protected i cannot understand.

 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The access specifiers are only related to the identifiers whose access they specify. Making a class public doesn't automatically make all its members public. So if making a class protected has no bearing on its members, then what use is this specifier? Making a top level class protected simply does not make sense on a conceptual level. The same is true for private.

Having said that, you should avoid the protected keyword as much as possible. If you don't know exactly whether its use is correct, it probably isn't. Preferably, you should make most members private or package private.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic