Java不支持多重inheritance吗?

让我们来看两个类的实例

public abstract class Shapes { public abstract void draw(Graphics g); } public class Rectangle extends Shapes { public void draw(Graphics g) { //implementation of the method } } 

这里的Rectangle类具有扩展类Shapes并且它隐式地扩展了Object类。 我知道没有其他扩展是可能的,但是我们不能调用inheritance类ShapesObject多重inheritance吗? (因为从一个角度inheritance两个类是多重inheritance)

它不是多重inheritance。 您不是从ShapesObject inheritance ,而是inheritance自作为Object Shapes

只有一次从2个类inheritance,才能进行多重inheritance。

 public class Rectangle extends Shapes, Figures 

Java中不允许这样做。

你所指的是多级inheritance 。 谢谢@BhavikShah

您描述的是inheritance的定义。 一个类inheritance了它的超类的属性和方法,以及所有超类的超类。 返回根( Object )只有一条路径。 在多重inheritance中,将有多个路径返回到根(甚至多个根)。

这不像是从ShapesObject派生的Rectangle 。 但Rectangle派生自Shapes ,Shapes派生自Object ,因此RectangleShapeObject

  Object | V Shapes | V Rectangle 

因此,Java中没有多重inheritance

多重inheritance意味着在java中是不可能的

 public class A extends B, C { } 

直接在java中不能进行多重inheritance。

但是,您可以使用接口(在某种程度上)实现此目的。

例如

 interface A{ void m1(); } interface B{ void m2(); } class C implements A,B{ // it has both m1 and m2; }