An interface can extend another interface via the extends
keyword.
public interface BasicResourceService {
Resource getResource();
}
public interface ExtendedResourceService extends BasicResourceService {
void updateResource(Resource resource);
}
Now a class implementing ExtendedResourceService
will need to implement both getResource()
and updateResource()
.
Extending multiple interfaces
Unlike classes, the extends
keyword can be used to extend multiple interfaces (Separated by commas) allowing for combinations of interfaces into a new interface
public interface BasicResourceService {
Resource getResource();
}
public interface AlternateResourceService {
Resource getAlternateResource();
}
public interface ExtendedResourceService extends BasicResourceService, AlternateResourceService {
Resource updateResource(Resource resource);
}
In this case a class implementing ExtendedResourceService
will need to implement getResource()
, getAlternateResource()
, and updateResource()
.