• 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

How often do you use 'protected' variables?

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's been some time that I have been coding in Java now... but I still keep thinking: 'How often do people use the protected access modifier'. Typically, I just slam private in front of my variables and provide public accessor (setters and getters) methods to them. On a less frequent occurrence, I use public access fields when I don't want to be bothered by setters & getters (because they do nothing more than just set and return the variables - in a simple project). I use protected variables only rarely - mostly when I need subclasses to use a field in the superclass but don't want to have such field public.

My question is 'How often do you use protected variables? And in what scenarios (common/interesting) do you use them.
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
90% of the time I only use them as you've described, in a subclassing scenario.
 
reply
    Bookmark Topic Watch Topic
  • New Topic