Home  >  Article  >  Java  >  Can interface implement interface in java?

Can interface implement interface in java?

王林
王林Original
2020-05-15 11:04:174460browse

Can interface implement interface in java?

#Interfaces in Java cannot implement interfaces, but an interface can inherit one or more interfaces, which is similar to the inheritance method between classes.

The inheritance of the interface uses the extends keyword, and the sub-interface inherits the methods of the parent interface.

(Video tutorial recommendation: java video)

Inheritance of interface

The following Sports interface is interfaced by Hockey and Football Inheritance:

Can interface implement interface in java?

The Hockey interface declares four methods and inherits two methods from the Sports interface. In this way, the class that implements the Hockey interface needs to implement six methods.

Similarly, a class that implements the Football interface needs to implement five methods, two of which come from the Sports interface.

Multiple inheritance of interfaces

In Java, interfaces allow multiple inheritance.

In multiple inheritance of an interface, the extends keyword only needs to be used once, followed by the inherited interface. As shown below:

public interface Hockey extends Sports, Event

The above program fragment is a legally defined sub-interface. Unlike classes, interfaces allow multiple inheritance, and Sports and Event may define or inherit the same method.

Recommended tutorial: java entry program

The above is the detailed content of Can interface implement interface in java?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn