in Java, Reading Notes

TIJ chapter 6: Access Control

This chapter is not a complex one. It just tells the access control involved in Java.

There are 4 access level in Java, public, ¬†protected, package-private, private. (By accident they all start with letter “p”). Package-private is the default one without any modifier. The only thing one should note is the protected access level implies package-private ones(Actually this is true for all 4 levels, one implies the other one by order).

If one doesn’t allocate a package for a class, this class will belong to the default package. Default package in a same directory is viewed as one package.

People can make use of the access control to reach certain “design patterns”(which is in derision by C programmers). For instance, to create a class that only one instance is available.

Write a Comment

Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.