Ok, I'll give it a shot, though the best examples I think are Listeners. If you know anything about
Applets, you've used interfaces, and can learn from those.
Let's say you have an interface called Sleeper, which has a method isSleeping(). You also have classes Person, Fish, and Owl. I would not associate these classes normally, because besides being Animals, they don't have much in common (ok, I used to be a zoology major in undergrad and that statement just sounds so wrong, but for this example we'll use it). However, an object of each one of these classes has to sleep, but each has its own implementation of isSleeping()(people are somewhat fixed in their
patterns, fish sleep if the light isn't on in the tank, cats sleep whenever they darn well feel like it). So each class will
implement Sleeper, and use it's own implementation of isSleeping().
Now, if we have a program that has these objects doing something, and at some point in the program we want to call a method called
isAsleep( Sleeper s ). We can pass each object of the classes to this method, regardless of which class it is, and call the isSleeping() method, and each object will run its own implementation. But the nice thing is we don't have to specify Cat, or Person, or Fish. We just use Sleeper, and where ever Sleeper is, we can use those classes.
I would write the code out, but I have to run, have class tonight. This should give you a gist of what I was talking about earlier. Clear as mud?
For an excellent explaination of Interfaces, read Michael Matola's post at
http://www.javaranch.com/ubb/Forum19/HTML/000727.html Jason