java 和多重继承

java and multiple inheritance

我们可以将这段代码称为多重继承吗?

interface Interface {

    public int alpha = 0;
    public int calculA(int a, int b);
    public int calculB(int a, int b);
}

interface InterfaceA extends Interface {

    public default int calculA(int a, int b) {
        return a + b;
    }
}

interface InterfaceB extends Interface {

    public default int calculB(int a, int b) {
        return a - b;
    }
}

class TestInterface implements InterfaceA, InterfaceB {

    public TestInterface() {
        System.out.println(alpha);
        System.out.println(calculA(5, 2));
        System.out.println(calculB(5, 2));
    }

    public static void main(String[] args) {
        new TestInterface();
    }
}

看起来默认关键字允许多重继承。

这是正确的还是这个概念有另一个名字?

谢谢

编辑

它不是 Are defaults in JDK 8 a form of multiple inheritance in Java? 的副本,因为这个帖子讨论的是称为虚拟扩展的功能。

我的问题是问我的实现是叫多重继承还是别的.

Java不支持多重继承。

你目前所做的是实现多个接口,这是绝对允许的。

java 支持多重继承。

你正在做的是实施 interface您不能在 java 中扩展多个 class,但您可以实现多个接口

接口是引用类型,类似于class。它是抽象方法的集合。一个class实现了一个接口,从而继承了接口的抽象方法。接口还可以包含常量、默认方法、静态方法和嵌套类型。方法体仅存在于默认方法和静态方法中。

A class 描述对象的属性和行为,接口包含 class 实现的行为。

有关 interfaceclick here

的更多信息