3

Java Interface and Diamond problem

Java said to be solving the diamond problem using interface.
that is, look into the following program,



Now if you create a new class D extending Class B and C and call the show() method using the object of D, the compiler won’t know which method to call. i.e the show() method of class B or C. So Java does not support multiple inheritance for classes.

So in java the above problem is rectified by using interface.



Now it solved the diamond problem for methods. But still it did not solved diamond problem for variables. See the following program,



Now there is a ambiguous call for the variable i. The compiler don’t know which variable to call. i.e The variable i in Interface B or C.

 
Copyright © Arun's Blog
Design by Arunkumar