How to use sub-package in Java?

JavaJava Programming Java 8

Subpackages are similar to sub-directories. Consider an example. The company had a package that contained a source file, it would be contained in a series of subdirectories like this −


At the time of compilation, the compiler creates a different output file for each class, interface, and enumeration defined in it. The base name of the output file is the name of the type, and its extension is .class.

For example −

// File
public class Dell {
class Ups {

Now, compile this file as follows using -d option −


The files will be compiled as follows −


You can import all the classes or interfaces defined in \com\apple\computers\ as follows −

Published on 05-Feb-2018 11:28:51