Class (static) and object (instance) members
We have mentioned the term public members in relation to an object. We have also used the keyword static
while talking about the main()
method. We also stated that a member that is declared static
can have only one copy in JVM memory. Now, we are going to define all that, and more.
Private and public
The keywords private
and public
are called access modifiers. There are also default and protected
access modifiers, but we will talk about them in Chapter 7, Packages and Accessibility (Visibility). They are called access modifiers because they regulate accessibility to (sometimes also called visibility of) classes, methods, and fields, from outside the class, and also because they modify the declaration of the corresponding class, method, or field.
A class can be private when it is a nested class only. In the preceding Java class section, we did not use an explicit access modifier for nested classes (thus, we used the default one), but we could have...