Java class defines interfaces internal

 

Java class defines the internal interfaces, further action can be seen as complementary functionality class, the class which consists of two parts: a fixed part of their part may vary, and this variable portion to a programming interface.

Another role is to avoid naming conflicts.

 

Examples

Fruits like Apple internal interfaces exist

public class Fruits {

    public interface Apple {
        public String info();
    }

}

 

Apple implement interfaces Fruits class by way of anonymous inner classes

public class Test {

    public static void main(String[] args) {
        Fruits.Apple apple = new Fruits.Apple() {
            @Override
            public String info() {return "I'm an Apple";}
        };
        System.out.println(apple.info());
    }
}

 

It should be noted, with or without internal interface declared static, are static. This is different from members of inner classes , class members inside it relies on an object in the class implementation.

 

Guess you like

Origin www.cnblogs.com/deltadeblog/p/11281439.html