Home> Java> JavaBase> body text

Can interface implement interface in java?

王林
Release: 2020-05-15 11:04:17
Original
4382 people have browsed it

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!