This code works perfectly. The method test() works for both interfaces. What is exactly going on under the hood? And how is this feature useful in practical scenario?
class C implements A, B
public void test()
A a = new C();
B b = new C();
Because it's an interface there is no harm done. You're basically using a blueprint for your
C class by implementing
B say that
C should implement a method called
C class implements that method, so the interfaces have done their job.
It's basically your
C class saying: "Oh hey, I need to implement
test() because of interface
A" and you implement it. Then your
C class says "Oh hey, I need to implement
test() again because of interface
B" and it sees that there is already a method called
test() implemented so it's satisfied.
You can also find more information here: JLS §18.104.22.168