Interface members

suggest change
public interface MyInterface {
    public void foo();
    int bar();

    public String TEXT = "Hello";
    int ANSWER = 42;

    public class X {
    }

    class Y {
    }
}

Through Java 8, interface members are public even when the public keyword is omitted. Methods with no body are also abstract. Fields are public static final, and nested types are public static. So foo(), bar(), TEXT, ANSWER, X, and Y are all public. Java 9 also allows private interface methods.

Access can still be limited by the interface itself. MyInterface is public, so its members may be accessed from anywhere. If MyInterface were package-private, its members would be accessible only from the same package.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents