How to use a class from a parent directory in Java?

后端 未结 3 1833
感动是毒
感动是毒 2021-01-15 01:43

For example, I have a class called Foo inside Foo.java which will use a class called Bar inside ../Bar.java. Is there any

3条回答
  •  既然无缘
    2021-01-15 02:15

    Your classes have packages, which are mirrored in the directory structure. E.g. com/company/pk/Foo and com/company/Bar - then you can reference them using the import statement. If your classes are in different directories but don't declare a package, then you are doing it wrong.

    Read about packages

提交回复
热议问题