This is called package compaction and works at the jar file level.
From the official trail:
Packages in JAR files may optionally be sealed, which means that all classes defined in this package must be archived in the same JAR file . For example, you can seal a package to ensure version consistency between classes in your software.
To clarify: since classes must come from the same jar file, no one can add classes to your package since new classes will not come from your jar file.
source share