Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the mechanism of interface multi-inheritance in Java

Shulou Source: shulou.com Published: 2022-06-01 17:52:04 10月21日 Update

This article mainly introduces what is the interface multi-inheritance mechanism in Java. It is very detailed and has a certain reference value. Friends who are interested must read it!

Cause of the problem

Today, when I was looking at the collection source code, I suddenly saw that the interface inherited the interface, and I felt a little different. in the past, writing code is that the class inherits a class and implements the interface. When I wrote so much, I was a little surprised to see that the interface inherited the interface. I thought there was something wrong with it. As for the test, I consulted some information.

An interface can inherit multiple interfaces at the same time

Writing interface test

Public interface Jiekou extends Jiekou1,Jiekou2 {void jiekou ();} public interface Jiekou1 {void jiekou1 ();} public interface Jiekou2 {void jiekou2 ();} public interface Jiekou3 {void jiekou3 ();}

As mentioned above, there is no problem, so Java supports interface multi-inheritance

Interface cannot implement any interface

Code verification

Public interface Jiekou implements Jiekou2 {void jiekou ();}

As shown in the figure, No implements clause allowed for interface

As above-the interface cannot implement any interface

A class can implement multiple interfaces

Class implements multi-interface code

Public class Aggregate implements Jiekou,Jiekou3 {@ Override public void jiekou () {} @ Override public void jiekou1 () {} @ Override public void jiekou2 () {} @ Override public void jiekou3 () {}}

There is no problem for the above class to implement multiple interfaces.

A class can inherit only one parent class

First build the parent and subclass code

Public class FatherOne {} public class FatherTwo {} / Class inherits a class is not a problem public class Son extends FatherOne {}

If you have more than one class, you will be prompted: Class cannot extend multiple classes

The above is all the content of the article "what is the interface multi-inheritance mechanism in Java?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Interface code problem multiple such as above mechanism content article hint test no surprise that is value interest reason at the same time subclass boy partner Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Apple NVidia MySQL OPPO Reno