Sobes.tech
Junior — Middle

Can the public modifier and the abstract keyword be omitted in the declaration of an interface method?

sobes.tech AI

Answer from AI

In Java, starting from version 8, it is possible to omit the public modifier and the abstract keyword in interface method declarations, since all methods in an interface are public abstract by default (except for methods with implementations — default and static).

That is, these two options are equivalent:

interface MyInterface {
    void doSomething(); // by default public abstract
}

interface MyInterface {
    public abstract void doSomething();
}

Both declarations mean that the method must be implemented in the class that implements the interface.

However, for code readability, it is often explicitly stated public (but abstract is usually omitted).