Junior — Middle
Is it possible to implement two interfaces containing the same method declarations in one class?
sobes.tech AI
Answer from AI
Yes, in Java, it is possible to implement two interfaces in a single class that contain the same method declarations. Since interfaces only contain method signatures (without implementation), a class implementing both interfaces must provide a single implementation for these methods.
Example:
interface InterfaceA {
void doSomething();
}
interface InterfaceB {
void doSomething();
}
public class MyClass implements InterfaceA, InterfaceB {
@Override
public void doSomething() {
System.out.println("Implementation of doSomething method");
}
}
Thus, no conflicts arise, and the class implements the method only once for both interfaces.