File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Cattle Drive and the fly likes import an interface? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "import an interface?" Watch "import an interface?" New topic

import an interface?

Carol Murphy
village idiot

Joined: Mar 15, 2001
Posts: 1202
I'm looking over, one of the classes included in jr.jar. I just discovered that the import statement in this class is actually importing an interface, not a class. When you import an interface, do you still have to implement it? I just read that the container is responsible for implementing this particular interface, but I was only aware that interfaces were implemented, not imported! If you do import a different interface in some other class, would you then have to implement it, or how would that work?
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
No, when you import an interface, you DO NOT have to impelment it. On the other hand, if you implement an interface, you DO have to import it if the interface is declared in a different package than the class that implements it.

To help you understand this, the import statement simply tells the current file which classes and/or interfaces are available to be used. (Okay, there is a little more to it than this, but I'm trying to keep it simple.) Or in other words, whenever you USE a class or interface that belongs to a different package, you MUST import it. It makes no difference whether you use the class or interface as a local variable, member variable, or if you extend a class or implement an interface. In each case, you need to tell the compiler where to find the class or interface. This is what the import statement is for.


Java API Documentation
The Java Tutorial
Carol Murphy
village idiot

Joined: Mar 15, 2001
Posts: 1202
Hmmmm. That's very interesting! Thanks Layne!
I agree. Here's the link:
subject: import an interface?
It's not a secret anymore!