Course contentsShow
← Java
Lesson 665 of 2,87016. Packages, Imports, and JAR FilesFree lesson

Package Hierarchies Are Not Inheritance

com.example.util and com.example.util.math are separate packages with no special relationship or visibility.

Package Hierarchies Are Not Inheritance

You'll learn why nested package names like com.example.util and com.example.util.math don't create any special relationship between packages.

The Misconception

When you see packages named like this:

com.example.util
com.example.util.math
com.example.util.collections

It looks like a hierarchy—like com.example.util.math is somehow "inside" or "extends" com.example.util. This is completely false.

The Reality

In Java, these are entirely separate, independent packages with no special relationship whatsoever. The dots in package names are just naming conventions for organization—they don't create any parent-child relationship.

What This Means in Practice

  • Classes in com.example.util.math have no automatic access to package-private members of com.example.util
  • An import of com.example.util.* does not import anything from com.example.util.math
  • There is no inheritance of visibility or permissions

Helpful Analogy

Think of packages like separate folders on your computer. Just because you have:

  • /documents/work/
  • /documents/work/reports/

doesn't mean files in reports/ can magically access files in work/ without going through normal file system permissions. They're distinct locations that happen to share a naming pattern.

The naming convention (com.example.util.*) is purely for human organization—to help developers see related functionality at a glance. The Java compiler treats each package as a completely isolated namespace.

Key Takeaway: Package names with dots create a visual hierarchy for humans, but Java treats each package as completely independent—there's no inheritance, no special access, and no automatic imports between "nested" packages.