Skip to content

Package Visibility Issue in Java


I am trying to build a java project from command line with the following directory structure :



I assume that has access to all classes, enums, interfaces, and annotations of all the four folders. But, if I want to use the enum in tokens package, is there any way to do so ? By way, I mean what access specifiers should I use to fulfill my use case ?

LINKS which I used before asking this question :




Thanks in advance.

EDIT : Main can import from packages and main is in default package.


Assuming you are using java8 and before:

  1. Main will not have access to all classes and enum by default
  2. Main will have access to classes and enums defined within
  3. A method in Main will have access to inner classes and enums
  4. Main will have access to classes and enums defined as public in other packages
  5. Main will have access to classes that it is extending in other packages(they should be atleast protected)

Similar access policy will be followed for other classes too. (Main has nothing special)

Please refer

  1. Tutorials
  2. Modifiers