To implement multiple interfaces in Java, you can use the implements
keyword followed by a comma-separated list of the interfaces that you want to implement.
Here is an example of how to implement two interfaces in a class:
public class MyClass implements Interface1, Interface2 { // Implementation of methods from Interface1 and Interface2 }
In this example, the MyClass
class implements both the Interface1
and Interface2
interfaces. This means that the MyClass
class must provide an implementation for all of the methods declared in these interfaces.
If the interfaces have methods with the same signature, the implementing class must provide a single implementation for those methods.
For example:
public interface Interface1 { void foo(); } public interface Interface2 { void foo(); } public class MyClass implements Interface1, Interface2 { public void foo() { // Implementation of foo() } }
In this example, both the Interface1
and Interface2
interfaces declare a foo()
method. The MyClass
class must provide a single implementation for this method that satisfies both interfaces.