Let's look at the following code
interface P { public void doSomething(); } interface Q { public void doSomething(); } class A { public void doSomething() { } } class B { public void doSomething() { } } class C implements P,Q { public void doSomething(){
now, to use the C object, you have a doSomething() implementation in class C. This is only implemented in class C.
But if you could create a D object and call doSomething , which method should you call? since this method is implemented in both A and B.
The problem with diamonds
actually a real diamon task
class A { public void doSomething() { } } class B extends A{ public void doSomething() { } } class C extends A{ public void doSomething() { } } class D extends B,C {

it is called a diamond because of this diamond shape. Here if you want to do the following
D d = new D(); d.doSomething();
From wikipedia here is a good real-time example
For example, in the context of GUI software development, the Button class can inherit from both the Rectangle (for appearance) and Clickable (for handling functions / input) and the Rectangle and Clickable classes both inherit from the Object class. Now, if the equal method is called for the Button object, and there is no such method in the Button class, but there is an overridden equal method in both Rectangle and Clickable, which method should be called in the end?
source share