Thinking in Java Fourth Edition Bruce Eckel Chapter 5 Exercise 9

Exercise 9: Create the following file in the access/local directory (presumably in your CLASSPATH):

package access.local;
class PackagedClass
{
    public PackagedClass()
    {
        System.out.println("Creating a packaged class");
    }
}
package access.foreign;
import access.local.*;

public class Foreign
{
    public static void main(String[] args)
    {
        PackagedClass pc = new PackagedClass();
    }
}

Output:

Compiler error because: PackagedClass in not public, so no access outside of package. Moving Foreign to local would allow package access to PackagedClass.

Leave a Reply

Your email address will not be published. Required fields are marked *