why we not use multiple inheritance in java???????????????????/

------------------------------------------------------------------------------------------

  • Brahma Prakash Shukla
  • Brahma Prakash Shukla
  • |
  • 17 Mar
  • |
  • 215 Views
  • |
  • 18 Answers

text limit upto 4000

  • 4

    firstly , java don't support multiple inheritance because if class A contain a method ABC() if class B also contain method ABC() ..then these both classes are to be extended to the Class C then compiler get confuse which class method ABC () is to be called ..so to avoid this ambiguity ,java doesn't support it

    • Voted By:
    • Himanshi ,
    • Vikas ,
    • Anil ,
    • Kuchipudi ,
    • Rakesh

  • 0

    Java don't support multiple inheritance because it has ambiguity. The famous diamond problem in which class A is derived by two class B & C . It's called hierarchical inheritance. Now D is derived by B and C assuming java supports multiple inheritance. Now D is using a method of class A but it's immediate parent is class B and C so ultimately it use method of B or C but B and C both inherit A so D has confusion among which method it is going to use. And if the method is overridden by B or C then there will ne more chaos so java didn't support multiple inheritance.


  • 0

    Due to Diamond problem.


  • 0

    Becouse of simplicity there is no direct concept of Inheritance of java.        


  • 0

    To avoid Diamond Problem.


  • 0

    java supports multiple inheritance through interfaces only. A class can implementany number of interfaces but can extend only one class. Multiple inheritance is notsupported because it leads to deadly diamond problem. 


  • 0

    java supports multiple inheritance through the interface concept .But they are not using multiple inheritance why because if two classes have the same methods means the compiler dont know which method to be called so it will create ambiguity thts why we dont use it.


  • 0

    To reduce the complexity and simplicity the multiple inheritance is not supported in java.
    Consider a scenario where A,B and C are three classes. The C class inherits A and B classes. If A and B classes have same method and you call it from child class object, there will be ambiguity to call method of A or B class.
    Since compile time errors are better than runtime errors, java renders compile time error if you inherit 2 classes. So whether you have same method or different, there will be compile time error.

    Read:- Why Java Doesn’t Support Multiple Inheritance


  • 0

    Because java provides a robust and secured,simple solutions and including multiple inheritance in java would lead to ambiguity and complex structure.E.g - If we have one class as class B which inherits from class A and class C,then which parent class characteristics would class B inherit??..This is the problem with multiple inheritance and java supports it with interface and not with class!


  • 0

    It is due to the "Diamond Problem", now the question arises what the hack is a "Diamond Problem"?

    1. It will cause an ambiguity if both the classes have the same method or variable name then which one to be called by the SubClass.

    2. In the Constructor of a SubClass if "super" keyword is used then there will be ambiguity that to which superclass constructor should be called.

    Hope it helped.

     


  • 0

    a class can implement any number of interfaces but can extend only one class. multiple inheritance is not supported because it leads to deadly diamond problem.


  • 0

    because it creates an ambiguity in java 


  • 0

    Bcoz of Java doesnt Support Multiple Inheritance Concept In java And Also Avoid the Ambiguity Problem in java .


  • 0

    to avoid the ambiguity problem in java


  • 0

    To avoid confusion we not use multiple inhertence in java


  • 0

    Because if we use multiple inheritance it will lead to ambiguity problem and which is also called diamond problem.It also causes lot of problem.


  • 0

    A class can implement any number of interfaces but can extend only one class. Multiple inheritance is not supported because it leads to deadly diamond problem


  • 0

    Because it create a ambuguilty problem.because of that we are not using multiple inheritanse in java.


Did Not Get The Answer? 
Contact people of Talent-Core Java directly from here