Originally posted by Jose Campana:
Hello Fellow Ranchers,
I'm having an issue with knowing how class access works when classes are in different packages.
The question I have is:
If I have an interface in one package(app.pack1), and that interface is public:
And I have a class that implements the Interface in another package(app.pack2).
Why do I have to import it(import app.pack1.MyInterface...) If the interface is public?
Could someone please explain to me these basics about packages?
Thank in advance,
Sincerely,
Jose
It is not necessary to use import in order to use an interface or class from a different package. One can use a public class or an interface from any package by using the fully qualified class name.
So in a
java file an import statement is simply a declaration of a shortcut
to indicate that you would like to use the class name alone instead of the
fully qualified class name through out a given java file.