0

I suspect I misunderstood some basic concept of packages in Java. Here is my hierarchy of the project:

  • Application (class with main)
  • Option (class)
  • Algorithm (Package)
    • PreProcessOptions (class)
    • GenerateImage (class)

Now, I would like that PreProcessOptions class will use Option class, to get all necessary data, but my IDE cannot find the class.

Any explanations? Thanks.

Palantiir
  • 55
  • 5

2 Answers2

0

Regarding Oracle Doc, access level modifiers determine whether other classes can use a particular field or invoke a particular method. There are two levels of access control:

  • At the top level—public, or package-private (no explicit modifier).
  • At the member level—public, private, protected, or package-private (no explicit modifier).

A class may be declared with the modifier public, in which case that class is visible to all classes everywhere. If a class has no modifier (the default, also known as package-private), it is visible only within its own package (packages are named groups of related classes — you will learn about them in a later lesson.)

Leandro Maro
  • 325
  • 1
  • 12
-1

Create a structure like this.

src
 -> main
     -> Application (class with main)
     -> Option (class)
 -> Algorithm (Package)
     -> PreProcessOptions (class)
     -> GenerateImage (class)

Now in your PreProcessOption class import the main package.

package Algorithm;
import main.Option;

Hope this will help.

Pirate
  • 2,886
  • 4
  • 24
  • 42
  • Thanks! that's helped. I created a new package called Application, and dragged Application.class and Options.class to that package. From there, I could access Options from PreProcessOptions. – Palantiir Mar 12 '20 at 12:46