Java: Can an interface extend another interface in Java?

Yes, an interface can extend another interface in Java. This is what the code for something like that would look like:

// this interface extends from the Body interface:
public interface FourLegs extends Body
  public void walkWithFourLegs( );


When would we want an interface to extend another interface?

Remember that any class that implements an interface must implement the method headings that are declared in that interface. And, if that interface extends from other interfaces, then the implementing class must also implement the methods in the interfaces that are being extended or derived from. So, in the example above, if we have a class that implements the FourLegs interface, then that class must have definitions for any method headings in both the FourLegs interface and the Body interface.

Hiring? Job Hunting? Post a JOB or your RESUME on our JOB BOARD >>

Subscribe to our newsletter for more free interview questions.