Since interfaces have no implementation of methods your nested interface does not need to be implemented when the outer interface gets implemented.
The inner interface is more like an interface located in a namespace of the outer interface.
To sum it up: The interfaces do not have any relation to each other you could handle them as you could two independent interfaces. The only relation is that you can only use interface B by calling A.instanceofB.method();
.
Interface:
interface OuterInterface {
String getHello();
interface InnerInterface {
String getWorld();
}
}
Example:
static class OuterInterfaceImpl implements OuterInterface {
public String getHello() { return "Hello";}
}
public static void main(String args[]) {
new OuterInterfaceImpl().getHello(); // no problem here
}
Example 2:
static class InnterInterfaceImpl implements OuterInterface.InnerInterface {
public String getWorld() { return "World";}
}
public static void main(String args[]) {
new InnerInterfaceImpl().getWorld(); // no problem here
}
Example 3:
static class OuterInterfaceImpl implements OuterInterface {
public String getHello() { return "Hello"; }
static class InnerInterfaceImpl implements InnerInterface {
public String getWorld() { return "World!"; }
}
}
public static void main(String[] args) {
OuterInterface oi = new OuterInterfaceImpl();
OuterInterface.InnerInterface ii = new OuterInterfaceImpl.InnerInterfaceImpl();
System.out.println(oi.getHello() + " " + ii.getWorld());
}