up previous next contents
Next: Creating Objects Up: Classes and objects Previous: Fields   Contents

Access Control and Inheritance

  • We declared many fields of Body to be public; this is not always a good design idea.
  • Four possible access control modifiers:
    • private - members declared private are accessible only in the class itself.
    • protected - accessible in the class itself, and are accessible to, and inheritable by, code in the same package, and code in subclasses.
    • public - accessible anywhere the class is accessible, and inherited by all subclasses.
    • package - members declared with no access modifier are accessible in the class itself and are accessible to, and inheritable by, code in the same package.


up previous next contents
Next: Creating Objects Up: Classes and objects Previous: Fields   Contents