【Content summary of the interface】

In the Java9+ version, the content of the interface can have:

1. Member variables are actually constants, format:

[public] [static] [final] data type constant name = data value;

Notice:

Constants must be assigned, and once assigned cannot be changed.

Constant names are fully uppercase, separated by underscores.

2. The most important thing in the interface is the abstract method, the format is:

[public] [abstract] return value type method name (parameter list);

Note: The implementation class must override all the abstract methods of the rewritten interface, unless the implementation class is an abstract class.

3. Starting from Java8, the default method is allowed to be defined in the interface, the format is:

[public] default return type method name (parameter list) {method body}

Note: Default methods can also be overridden

4. Starting from Java8, static methods are allowed to be defined in the interface, the format is:

[public] static return type method name (parameter list) {method body}

Note: It should be called through the interface name, and the static method of the interface cannot be called through the implementation class object

5. Starting from Java9, private methods are allowed to be defined in the interface, the format is:

Ordinary private method: private return value type method name (parameter list) {method body}

Static private method: private static return value type method name (parameter list) {method body}

Note: The private method can only be called by the interface itself, and cannot be used by the implementation class or others.

Guess you like

Origin blog.csdn.net/m0_48114733/article/details/123469021