JAVA basic knowledge of their own understanding of the interface

Interface using the keyword interface.

The interface is not a class, the class attributes and methods are described in the object. The method comprising the interface. Interface no constructor can not be instantiated.

Interface methods are all abstract methods, no method thereof. Modified abstract methods are public abstract. Even without these two qualifiers earlier method, the default is public abstract.

In the interfaces may be variable, but the variable qualifier can only be public static final.

Class can implement an interface, use the keyword, implements. A class can implement multiple interfaces. All the methods in an interface class to implement. Otherwise, the class can only be declared to be abstract.

Code block can have a static or static method in an abstract class, but may in the interface.

All interface methods are certainly abstract methods, but all methods are static methods .java file is not necessarily the interface, there may be an abstract class.

Abstract class can only single inheritance. But the interface may be multiple inheritance, an interface can inherit multiple interfaces. When a class to implement the interface, the need to implement all the abstract methods all interfaces. (When there is an interface method A, it inherits the interface is also a method A, when the class implements the interface, only implement a method A).

Multiple inheritance between interfaces, an interface can inherit multiple interfaces, use a keyword extends, interface name subsequently separated by commas.

Class implements multiple interfaces, use a keyword implements, interface name subsequently separated by commas.

Static class methods can not be overridden, it can not be declared as abstract methods.

Static methods can be called directly by the method name .mothed way, but the interface can not be instantiated.

 

Published 15 original articles · won praise 0 · Views 1073

Guess you like

Origin blog.csdn.net/ma316110/article/details/79611214