JSR wrote:
> If class TestPackage and DefPack are in 2 separate files, how can we
> access DefPack from TestPackage?
>
> Note -
> 1. TestPackage is in package testapps and DefPack is in the default
> package space. This is the problem.
> 2. If I were to comment out the package statement within
> TestPackage.java, this example would compile.
> 3. I need to be able to compile with the pacakge specifications being
> the way they are.
You really can't do that. You can not import classes from the default (== no
package statement given) package. So you'll never be able to reach DefPack
from TestPackage.
The only solution is to put DefPack in a proper package.
>
> // Compilation unit - TestPackage.java
>
> package testapps;
>
> public class TestPackage {
> public static void main(String[] args) {
> new DefPack();
> }
> }
>
>
> // Compilation unit - DefPack.java
>
> public class DefPack {
> public DefPack() {
> System.out.println("DefPack created");
> }
> }
--
Kind regards,
Christophe Vanfleteren
|