Analysis of java interface definition and implementation method

This paper describes the definition and implementation of java interface. Share with you for your reference, as follows:

In Java, we can get the methods in another class through inheritance, but this only meets the requirement of inheriting one method. There are ways to inherit multiple methods. No, for example, some of our human genes are inherited from father and mother, while there are single inheritance in Java. What should we do? Java uses the interface method to solve the problem. If you implement the interface, you can realize the so-called multi inheritance

What is an interface?

A java interface (Interface) is a collection of method features. These method features come from specific methods. These methods generally come from some methods that constantly appear in the system. An interface only has the characteristics of methods, but does not have the implementation of methods. Therefore, when these methods are implemented in different places, they can have completely different behaviors. In the Java language, Java interfaces The port can also define public variables.

The interface separates the characteristics of the method from the implementation of the method. This division, The interface often represents a role, which packages the operations and properties related to the role, and the class implementing the interface plays the actor (class) of the role. A role (Interface) can be played by different actors (classes), and different actors (classes) play a common role (Interface) does not require anything in common.

be careful:

When people talk about "interface", the word often has two different meanings:

The first refers to the java interface, which is a structure existing in the Java language with specific syntax and structure. The second only refers to the feature set of methods possessed by a class, which is a logical abstraction.

Java interfaces can have public, static, and final attributes.

Let's take a look at the relevant features of the interface through the following example:

Operation results:

For more information about Java algorithms, readers who are interested can see the topics on this site: introduction and advanced tutorial of java object-oriented programming, tutorial of Java data structure and algorithm, summary of Java DOM node operation skills, summary of java file and directory operation skills, and summary of Java cache operation skills

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>