Java不支持多重继承吗? [英] Does Java not support multiple inheritance?

查看:216
本文介绍了Java不支持多重继承吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们接受两个类的实例

Lets us take instances of two classes

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 。我知道没有其他扩展是可能的,但我们不能调用继承类 Shapes 对象多重继承? (因为从一个角度继承两个类是多重继承)

Here the class Rectangle has extended class Shapes and implicitly it extends class Object. I know no other extension is possible, but can't we call inherited classes Shapes and Object multiple inheritance? (Since inheriting two classes is multiple inheritance from one perspective)

推荐答案

它不是多重继承。您不是继承自 Shapes Object ,您继承自 Shapes 这是一个对象

It isnt multiple inheritance. You are not inheriting from Shapes and Object, you are inheriting from Shapes which is an Object.

多重继承只有在你继承的情况下一次来自2个班级。

Multiple inheritance is only if you inherit from 2 classes at once.

public class Rectangle extends Shapes, Figures

Java中不允许这样做。

Which isnt allowed in Java.

您所指的是多级继承。谢谢@BhavikShah

What you are referring to is Multilevel Inheritance. Thanks @BhavikShah

这篇关于Java不支持多重继承吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆