Say I have an interface named MyInterface which contains two methods doSomething() and doSomethingElse() I would create the interface like this
Code:
public interface MyInterface{
void doSomething();
void doSomethingElse();
}
Then I'd use it like this
Code:
public class SomeClass implements MyInterface{
public void doSomething(){
// do some work
}
public void doSomethingElse(){
// do some work here too
}
//
// Anything else I want this class to have can go here
//
}
Then to actually use that class I'd do something like
Code:
public class SomeOtherClass{
public static void main(String[] args){
// I can either use a direct instantiation like this
SomeClass obj = new SomeClass();
obj.doSomething();
// When using direct instantiation I have direct access to
// everything that class has to offer, all methods (non private)
// all fields (non private) and so on and so forth
// Or I can use indirect instantiaion
MyInterface obj = new SomeClass();
obj.doSomethingElse();
// now I only have access to the interface methods
}
}
Interfaces are good with multiple inheritence, abstraction, and reflection. Hope this clarifies it a bit. Oh, and you can use as many interfaces as you like, just separate them by commas.