#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:
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!