Sobes.tech
Junior — Middle

Can you explain what the keyword 'implements' means in the Java programming language?

sobes.tech AI

Answer from AI

In Java, the keyword implements is used by a class to implement an interface. An interface defines a set of methods without implementation, and a class that implements this interface commits to implementing all its methods.

This allows creating flexible architectures where different classes can have a common set of methods defined by the interface but with different implementations.

Example:

interface Printable {
    void print();
}

class Document implements Printable {
    @Override
    public void print() {
        System.out.println("Print document");
    }
}

Here, the Document class implements the Printable interface and provides a concrete implementation of the print() method.

Can you explain what the keyword 'implements' means… - sobes.tech