Default Visibility
If you do not specify public or private for
a variable or a method,
then it will have default visibility.
Default visibility allows a variable or method to
be seen within all methods of a class or other classes that
are part of the same package.
These notes have not discussed packages yet.
A package is a group of related classes.
A later chapter will discuss how to create a package of classes.
For now, default visibility means
about the same thing as public visibility.
But it is best to explicitly declare members public
if that is what you actually need.
You can not explicitly declare a member of a class to have
default visibility
(for example, you can't say default int monthlyCharge; )
Later on after these notes have discussed inheritance there
will be other visibility modifiers,
and additional rules for public
and private visibility.
|