nested interfece

Java-Nested Interfaces

Nested Interfaces

An interface can be declared a member of a class or another interface. Such an interface is called a member interface or a nested interface. A nested interface can be declared as public, private, or protected. When a nested interface is used outside of its enclosing scope, it must be qualified by the name of the class or interface of which it is a member. Thus, outside of the class or interface in which a nested interface is declared, its name must be fully qualified. Here are some examples :

nested interfece
In the following program, ClassX defines a member interface called InterfaceY. Next, ClassY implements the nested interface by specifying “implements ClassX.InterfaceY”. Notice that the name is fully qualified by the enclosing class’ name.

Program

nested interfece nested interfece (2)

Program Source

class Interface {
    
    interface InterfaceOne{
        
        void call();
    }
}

class Test implements Interface.InterfaceOne {
    
    public void call()
    {
        System.out.println("call method called");
    }
}

public class Javaapp {

    public static void main(String[] args) {
        
        Test f = new Test();
        f.call();
    }
}

Leave a Comment