GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  J2EE  >  OOPS
Go To First  |  Previous Question  |  Next Question 
 OOPS  |  Question 3 of 30    Print  
why is multiple inheritance not allowed in java?

  
Total Answers and Comments: 20 Last Update: September 22, 2008     Asked by: swati 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: samjeyam
 
Found this reply by Tony Sintes (from Java World) :-

Whenever you find yourself asking why Java has or does not have some feature, consider the design goals behind the Java language. With that in mind, I started my search by skimming through "The Java Language Environment" by James Gosling and Henry McGilton (Sun Microsystems), a white paper published in May 1996 that explains some of the reasoning behind Java's design.

As the white paper states, the Java design team strove to make Java:

  • Simple, object oriented, and familiar
  • Robust and secure
  • Architecture neutral and portable
  • High performance
  • Interpreted, threaded, and dynamic


The reasons for omitting multiple inheritance from the Java language mostly stem from the "simple, object oriented, and familiar" goal. As a simple language, Java's creators wanted a language that most developers could grasp without extensive training. To that end, they worked to make the language as similar to C++ as possible (familiar) without carrying over C++'s unnecessary complexity (simple).

In the designers' opinion, multiple inheritance causes more problems and confusion than it solves. So they cut multiple inheritance from the language (just as they cut operator overloading). The designers' extensive C++ experience taught them that multiple inheritance just wasn't worth the headache.

Instead, Java's designers chose to allow multiple interface inheritance through the use of interfaces, an idea borrowed from Objective C's protocols. Multiple interface inheritance allows an object to inherit many different method signatures with the caveat that the inheriting object must implement those inherited methods. Multiple interface inheritance still allows an object to inherit methods and to behave polymorphically on those methods. The inheriting object just doesn't get an implementation free ride

Regards,
Sam

Above answer was rated as good by the following members:
Tarun Wadhwa
  Sorting Options  
  Page 1 of 2   « First    1    2    >     Last »  
October 01, 2005 00:04:57   #1  
pavan        

RE: why is multiple inheritance not allowed in java?

 pointers concept are not supported by java.and to reduce the code redundency

 


 
Is this answer useful? Yes | No
October 02, 2005 05:31:52   #2  
selvam_vivek        

RE: why is multiple inheritance not allowed in java?
To avoid ambiguity state.  
 
Is this answer useful? Yes | No
October 06, 2005 14:08:23   #3  
vijay        

RE: why is multiple inheritance not allowed in java?
By not allowing the inheritance of multiple base classes by a single subclass, Java greatly simplifies the inheritance model. Multiple inheritance carries with it several special cases that must be handled. This adds overhead to both the compiler and the run-time system, while providing only marginal benefit for the programmer.
 
Is this answer useful? Yes | No
December 09, 2005 04:40:34   #4  
manisha divate        

RE: why is multiple inheritance not allowed in java?

In multiple Inheritance,

ex: class A, Class B inherited from Class A, Class C inherited from class A, Class D inherited From Class B,and Class C.

in this Class D have dual copy of the methods ,datamembers defined in Class A, Vertual Function Is there in C++ but,again the pointer are not used in java.

So to avoid this ambiguity, only single chain inheritance is there, not multiple inheritance.


 
Is this answer useful? Yes | No
January 08, 2006 09:14:44   #5  
mahesh        

RE: why is multiple inheritance not allowed in java?
to reduse the complexcity in java.
 
Is this answer useful? Yes | No
September 27, 2006 06:39:24   #6  
lhariPrasad Member Since: September 2006   Contribution: 25    

RE: why is multiple inheritance not allowed in java?

Hi ,

Can any one solvethe diamond problem.

Assume there is a super class "Shape", Shape is extended into "Circle" and "Squre". Now I want to create a concrete class "CircleOnSqure" which extends both the Circle and Square.  How to implement this functionality in Java.

Hint : Java says Multiple inheritance can be done using Interfaces.

Regards,

Hari


 
Is this answer useful? Yes | No
December 07, 2006 10:27:26   #7  
Jetendra Ivaturi        

RE: why is multiple inheritance not allowed in java?

Due to the concept of overridding Java doesn't support multiple inheritance.

We have the concept of " Deadly Diamond of Death".

i.e., 

As we have an overridding concept in Java.

We know what overridding is, where the method name including parameters return types should be same.

If mutliple inheritance is provided in java.

eg:

A<- B,  A-<C  and now  B,C<-D

We have a method viz.   display() in A, we are overridding that in B and C. If D extends that two classes then if I call the display() then there will be ambiguity. To call which version of display().

As we dont have the concept of virtual functions, what we have in c++.

 

This is the reason why we dont have multiple inheritance in java.

 

 

 


 
Is this answer useful? Yes | No
April 27, 2007 05:56:30   #8  
ramesh        

RE: why is multiple inheritance not allowed in java?
Multiple inheritance is not allowed in java because it may lead to confusion for a programmer and this is against to java language to be a simple(one of the features of OOP's).Eg:class A extends B,C (not allowed in java)
class A extends B
class C extends A which is nothing but multiple inheritance, it means multiple inheritance can be achieved by repeated use of single inheritance.
2)we can also achieve multiple inheritance by using interfaces.

 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
May 25, 2007 05:54:13   #9  
Laxminarayana V        

RE: why is multiple inheritance not allowed in java?
You are saying that if D class is having the dual copy of methods then ambiguity will come, Suppose there is least chance of having dual copy of methods,Is it ok?
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
June 21, 2007 03:24:38   #10  
raja        

RE: why is multiple inheritance not allowed in java?
In java another form of multiple inheritance is Interface.
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
  Page 1 of 2   « First    1    2    >     Last »  


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape