Wednesday 27 March 2013

What is a Diamond problem in java? Why multiple inheritance is not supported in java?


Consider a class A has foo() method and then B and C derived from A and has their own foo() implementation.
Now class D derive from B and C using Multiple inheritance and if we refer just foo() compiler will not be able to decide which foo() it should invoke.
This is called as Diamond problem because structure on this inheritance scenario is similar to four edge diamond.
Also multiple inheritance causes problem in Constructor chaining, Casting.

No comments:

Post a Comment