<aside> πŸ’‘ Java has an organizational unit called package.

</aside>

Can use import to use packages directly: import java.math.BigDecimal

<aside> πŸ’‘ Note that * is not recursive. β†’ Cannot write : import java.* β†’ Will NOT import all packages in java.

</aside>


Creating and Naming Packages

The naming convention for packages in java is similar to Internet Domain name, but in reverse:


Add a package header to include a class in a packge:

package in.ac.iitm.onlinedegree;

public class Employee { ... }
// This class is now available in the above defined package.

<aside> πŸ’‘ By default, all classes in a directory belong to the same anonymous package.

</aside>


More About Visibility

<aside> πŸ’‘ If we don’t specify modifiers, the default visibility is public within the package. (Applies to both methods and variables)

</aside>

We can also restrict visibility with respect to the class inheritance hierarchy β†’ i.e, visibile to subclasses only.