Only the enclosing class can access a Static Nested interface.
Consider following code in which interface Xyz is enclosed in
class Abc.
public class Abc {
public interface Xyz {
void callback();
}
public static void registerCallback(Xyz xyz) {...}
}
// Client Code
Abc.registerCallback(new Abc.Xyz() {
public void callback() {...}
});
Any code that cannot access Abc can not access interface Xyz also.
So the purpose of declaring an Inner interface is to restrict its
access from outside world
xxxxxxxxxx
class A{
interface Message{
void msg();
}
}
class TestNestedInterface2 implements A.Message{
public void msg(){System.out.println("Hello nested interface");}
public static void main(String args[]){
A.Message message=new TestNestedInterface2();//upcasting here
message.msg();
}
}