Why is there no multiple inheritance in Java, but implementing multiple interfaces is allowed?

后端 未结 18 1985
囚心锁ツ
囚心锁ツ 2020-11-22 14:55

Java doesn\'t allow multiple inheritance, but it allows implementing multiple interfaces. Why?

18条回答
  •  不知归路
    2020-11-22 15:38

    Java does not support multiple inheritance , multipath and hybrid inheritance because of ambiguity problem:

     Scenario for multiple inheritance: Let us take class A , class B , class C. class A has alphabet(); method , class B has also alphabet(); method. Now class C extends A, B and we are creating object to the subclass i.e., class C , so  C ob = new C(); Then if you want call those methods ob.alphabet(); which class method takes ? is class A method or class B method ?  So in the JVM level ambiguity problem occurred. Thus Java does not support multiple inheritance.
    

    multiple inheritance

    Reference Link: https://plus.google.com/u/0/communities/102217496457095083679

提交回复
热议问题