Showing posts with label Java Member accessibility/visibility modifiers for classes. Show all posts
Showing posts with label Java Member accessibility/visibility modifiers for classes. Show all posts

Monday, 8 June 2015

Java Member accessibility/visibility modifiers for classes

By specifying member accessibility modifiers a class can control what information is accessible to clients (i.e. other classes). These modifiers help a class to define a contract so that clients know exactly what services are offered by the class.

Accessibility/visibility of members can be one of the following:

  • public
  • protected
  • default (also called package accessibility)
  • private

Note: Member accessibility modifier only has meaning if the class (or one of its subclasses) is accessible to the client. Also note that only one accessibility modifier can be specified for a member. The discussion applies to both instance and static members of classes.