Search code examples
javainterfacenestedimplements

What happens when implementing Parent interface that declares a Nested Interface


I searched Google but couldn't find a specific example that clears my doubt. Suppose I have a parent interface with nested interface.

E.g

public interface A {
    .. methods

    interface B {
        .. methods
    }
}

If a class implements interface A, what happens, does that class internally implements the nested interface B as well, that means am I supposed to override interface B's methods too?


Solution

  • No. The inner interface has to be implemented.

    Syntax would be

    Class C implements A, A.B{
    // add methods here
    }
    

    If you implement only A, you are fine with only declaring A's method without B interface methods.