Class extending more than one class Java?

后端 未结 11 1567
执笔经年
执笔经年 2020-12-06 04:29

I know that a class can implement more than one interface, but is it possible to extend more than one class? For example I want my class to extend both TransformGroup<

11条回答
  •  情书的邮戳
    2020-12-06 05:24

    Java does not allow extending multiple classes.

    Let's assume C class is extending A and B classes. Then if suppose A and B classes have method with same name(Ex: method1()). Consider the code:

    C obj1 = new C(); obj1.method1(); - here JVM will not understand to which method it need to access. Because both A and B classes have this method. So we are putting JVM in dilemma, so that is the reason why multiple inheritance is removed from Java. And as said implementing multiple classes will resolve this issue.

    Hope this has helped.

提交回复
热议问题