A summary of the interfaces in Java:
Reference Link: http://www.cnblogs.com/dolphin0520/p/3811437.html
1. Definition of the interface:
interface is the declaration of a series of methods, an interface only the characteristics of the method is not implemented in a specific way, so these methods can be implemented in different places by different classes, and these implementations can have different behavior (function).
2. Representation of the interface:
The interface is represented by the keyword interface:
Format: [modifier] Interface interface Name {}
Interface demo{}
3. Implementation of the interface:
The interface implementation uses implements to represent:
Format: Class name implements interface name {}
Public class Implements demo{}
4. Features of the interface:
A: The interface cannot be instantiated and can be instantiated in a polymorphic manner;
B: The subclass of an interface can be an abstract class or a concrete class, but the concrete class overrides all abstract methods in the interface;
C: Methods in the interface are implicitly specified as public abstract methods and can only be public abstract methods;
D: The variables in the interface default to static constants public static final, cannot be modified;
E: The interface has no construction method;
5. The difference between an interface and an abstract class:
1). Abstract class is an abstraction of a thing, that is, an abstraction of a class, and an interface is an abstraction of a behavior, that is, an abstraction of a method.
2). Abstract classes can have specific member methods, and only abstract methods exist in interfaces;
3). member variables in an abstract class can be of various types, whereas member variables in an interface are only public static final types;
4). The interface cannot contain static code blocks and static methods, while abstract classes can have static blocks and static methods;
5) A class can inherit only one abstract class, while a class may implement multiple interfaces.
6). Abstract class If you need to add a new method, you can add a concrete implementation directly in the abstract class, the subclass can not be changed, and the interface is changed, all the classes that implement this interface must be modified accordingly.
Here is an implementation case for an interface:
1 Interfacetest{2 Public Abstract voidmethod ();3 }4 //implementation of the interface class:5 Public classDemoImplementsTest {6 7 Public Static voidMain (string[] args) {8Demo d =NewDemo ();9 D.method ();Ten } One A Public voidmethod () { -System.out.println ("Method"); - } the}
Understanding of Java Interfaces