top of page
Writer's picturesibi a o

How to resolve diamond problem in java using interface?

First of all, understand what a diamond problem is. It is an ambiguity that arises due to multiple inheritance. For instance, when two classes B and C inherit from A and another class D inherits from both classes B and C, this is called a diamond problem.


when trying to create multiple inheritance, it will create ambiguity. Ambiguity is when the compiler gets confused if there are multiple inheritance. To avoid ambiguity due to multiple inheritance in Java classes, interfaces can be used. Interfaces support multiple inheritance.


how can resolve diamond problem with interface.


We have created an interface A with display method.


We have created an interface B which extends interface A with display method.


We have created another interface C which extends interface A which has a display method.


D is a class which implements both interfaces B and C. In this we have to over ride which method we need to use for display


In this Main class which create an object D which use display method from class D



10 views0 comments

Recent Posts

See All

Comentários


bottom of page