Class extending more than one class Java?

后端 未结 11 1533
执笔经年
执笔经年 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:08

    Multiple inheritance is not possible with class, you can achieve it with the help of interface but not with class. It is by design of java language. Look a comment by James gosling.

    by James Gosling in February 1995 gives an idea on why multiple inheritance is not supported in Java.

    JAVA omits many rarely used, poorly understood, confusing features of C++ that in our experience bring more grief than benefit. This primarily consists of operator overloading (although it does have method overloading), multiple inheritance, and extensive automatic coercions.

    0 讨论(0)
  • 2020-12-06 05:09

    No it is not possible in java (Maybe in java 8 it will be avilable). Except the case when you extend in a tree. For example:

    class A
    class B extends A
    class C extends B
    
    0 讨论(0)
  • 2020-12-06 05:11

    There is no concept of multiple inheritance in Java. Only multiple interfaces can be implemented.

    0 讨论(0)
  • 2020-12-06 05:12

    In Java multiple inheritance is not permitted for implementations (classes) only for interfaces:

    interface A extends B, C
    

    E.g. MouseInputListener extends MouseListener and MouseMotionListener

    And, of course, a class can implement several interfaces:

    class X implements A, F
    
    0 讨论(0)
  • 2020-12-06 05:12

    Hello please note like real work.

    Children can not have two mother

    So in java, subclass can not have two parent class.

    0 讨论(0)
  • 2020-12-06 05:13


    Assume B and C are overriding inherited method and their own implementation. Now D inherits both B & C using multiple inheritance. D should inherit the overridden method.The Question is which overridden method will be used? Will it be from B or C? Here we have an ambiguity. To exclude such situation multiple inheritance was not used in Java.

    0 讨论(0)
提交回复
热议问题