Implementing multiple interfaces in JAVA

In another article I already described interfaces in JAVA and demonstrated how interface implementation. In this article, I demonstrate how you can implement multiple interfaces in one implementation class.

Two JAVA interfaces are defined below:

interface Person {

  public void voice(); // interface method (no body)

}

interface Mammal {

  public void rest(); // interface method (no body)

}

For access interface methods must be implemented. This is facilitated with the implements keyword. This is in fact similar to inheritance, which is facilitated with the extends keyword.

When implementing the interface the method body must then be specified. The class implementing the interface can be referred to as implement class or implementation class.

Here is an example with such an implementation class:

// Man class implements Person interface

class Man implements Person, Mammal {

  public void voice() {

    // voice interface method implemented by specifying body

    System.out.println(“Deep dark voice");
  
  }

  public void rest() {

    // voice interface method implemented by specifying body

    System.out.println(“resting");

  }

}
Close

Meta