Tuesday, April 10, 2007

Why does Java not support Multiple Inheritance?

Java does not support multiple inheritance atleast not the way it does in case of C++.In designer’s view Multiple Inheritance poses many problems and confusions than it solves.e.g. famous Diamond problem The diamond problem is an ambiguity that can occur when a class multiply inherits from two classes that both descend from a common super class. In such scenarios assuming if Java implements multiple inheritance then it would be difficult to know which method is to be called by an inheriting class object of two of the super classes. In Java, interfaces solve all these ambiguities caused by the diamond problem. Through interfaces, Java allows multiple inheritance of interface but not of implementation. Implementation, which includes instance variables and method implementations, is always singly inherited. As a result, confusion will never arise in Java over which inherited instance variable or method implementation to use.

9 comments :

Anonymous said...

good post

Anonymous said...

Thanks.

Poonam on August 2, 2011 at 9:28 AM said...

good post..!! Thanks!!...

susant on August 5, 2011 at 10:25 PM said...

very nice answerss...

ek_rk on October 2, 2011 at 7:14 PM said...

thanks it is really helpful

ek_rk on October 2, 2011 at 7:14 PM said...

its really helpful

Anonymous said...

Really Helpful.. Thanks!!!

Anonymous said...

one more reason i think related to
1. dynamic class loading
2. garbage collection

sid on November 6, 2012 at 10:27 PM said...

very good..

 

Disclaimer
Interview Questions On Java,Java EE Copyright © 2016. Reads: best tracker