JAVAOOP interface (interface)

interface is generally mainly used to describe individual methods, for example:

public interface eat{};

Implements class and interface docking keywords, for example:

public class cat implements eat{}

Features of the interface

1. The interface cannot be instantiated
2. The implementing class must implement all methods of the interface
3. The implementing class can implement multiple interfaces
4. The variables in the interface are static constants


Interface classes have better features than abstract classes:

1. Can be multi-inherited
2. Complete separation of design and implementation
3. More natural use of polymorphism
4. Easier to build a program framework
5. Easier to replace implementation


step:

Writing an Interface
Implementing an Interface Implementing an Interface
Using Polymorphism


How interfaces implement polymorphism:

1. The interface is implemented as a method parameter
2. The interface is implemented as a method return value

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324783902&siteId=291194637