Hi everyone.
Welcome back to this tutorial.
In this tutorial, we will code and explore some of the issues that we might face with the introduction
of multiple interfaces.
In order to demonstrate this, I'm going to create an interface.
All interface for.
And.
We take a look at it Interface one and interface four have the similar methods.
Right?
I'm going to create an implementation class called client one four.
Okay.
This is going to implement interface one and interface four.
That's the reason why I named it as client one four.
So this is going to implement.
The interface one and interface for.
As soon as I do it, we take a look at it is giving some compilation issue.
.14 inherits unrelated default methods for method A from types interface one and interface for.
The reason why we get this compilation issue is that it has a method called.
Method A.
Basically, interface one has a method called method A and interface four also has a method called method
A with a similar kind of method signature.
Now Java is so confused and it is not sure which method it needs to resolve when we call that.
So the actual expectation in these kind of scenarios is that you have to implement that method basically
not implement.
You have to override that method in the actual implementation class.
That's the only way to resolve this kind of issues.
So this is something which you have to keep in your mind whenever you are implementing interfaces.
If both the interface have a similar method and the only way to solve these kind of issues is to implement
that method in the implementation class itself.
And thus I'm going to name this one as client.
One for class.
Now let's call this one.
Create an instance.
Line one for line, one for equal to new client one.
For now, call the method.
Wanna run this one?
You take a look at it, it printed the result as expected.
So this is one thing which you have to keep in your mind.
If you have two methods of similar method signature, then you have to override the similar method in
your implementation class.
With this, we came to the end of this tutorial.
Thank you for watching.