This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Please help me to understand interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Please help me to understand interfaces" Watch "Please help me to understand interfaces" New topic

Please help me to understand interfaces

t andrews

Joined: Oct 29, 2003
Posts: 2
I guess I am having difficulty understanding the �why� of interfaces and I would really appreciate someone helping to clear this up for me. I understand that interfaces can inherit from other interfaces and that classes can implement multiple interfaces and I understand that this is a key difference between interfaces and inherited classes. What I don�t get is why you actually use interfaces and this is where I�m coming from. Interfaces contain no code bodies and all the methods for an interface must be implemented in the class. This confuses me because I don�t understand why the interface is used if the class has to write the implementation for all of the methods. Obviously I am missing something that is really profound; please help me to understand why the interface is used instead of just writing the members needed with no reference to an interface.
Junilu Lacar

Joined: Feb 26, 2001
Posts: 4446


Junilu - [How to Ask Questions] [How to Answer Questions]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
The answers to "why use interfaces" or "why use polymorphism" will take you into all the coolest OO theory. If you're writing two or three classes to satisfy an assignment you might not run into a need. But in architecting larger systems you can add major goodness with some advanced techniques. Drop down to the OO, UML and other cool stuff forum for that kind of talk.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: Please help me to understand interfaces
Similar Threads
Use of Interface
Interface vs. abstract class in UML and in Java; role of TO, VO
Few simple questions
�uncommon� methods declared in the javax.ejb.EJBContext interface